0

我正在使用 aAVPlayer来显示视频。我希望确保用户一直看到视频直到结束。

使用

NotificationCenter.default.addObserver(self, selector: #selector(playerDidFinishPlaying), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: playerVC.player?.currentItem)

我能够知道视频何时结束,但问题是用户可以使用播放控制器拖动到视频的末尾。

我认为这NSNotification.Name.AVPlayerItemTimeJumped是解决方案,但即使视频正常播放,也会发布此通知。我的意思是:

NotificationCenter.default.addObserver(self, selector: #selector(playerItemTimeJumped), name: NSNotification.Name.AVPlayerItemTimeJumped, object: playerVC.player?.currentItem)

@objc func playerItemTimeJumped(note: NSNotification) {
        hasTimeJumped = true
        print("Time has jumped !")
}

“时间跳跃了!” 即使我在没有触摸任何东西的情况下观看视频也会被打印出来。这种行为正常吗?如果是,我如何检查用户是否连续观看视频直到结束?我是否被迫创建一个计时器变量并检查该变量是否大于视频的长度?

亲切的问候

4

0 回答 0