【发布时间】:2021-02-28 21:18:17
【问题描述】:
我有一个AVPlayer,当我到达持续时间结束时,我想回到开始,但我不想重新启动AVPlayer。
//Do something when video ended
NotificationCenter.default.addObserver(self, selector: #selector(playerDidFinishPlaying(note:)), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: nil)
@objc func playerDidFinishPlaying(note: Notification) {
self.restartVideo()
}
func restartVideo() {
self.player.seek(to: .zero, toleranceBefore: .zero, toleranceAfter: .zero)
}
从这里,我可以简单地.play() 和AVPlayer,它会从头开始播放。但是,在我之前.play(),.seek() 函数并没有向用户表明它已被重置回开始。在我执行.play() 之后,AVPlayer 帧实际上不会转换回第一帧。
问题:
在使用.seek() 功能时,如何让AVPlayer 更改它向用户显示的实际帧?
【问题讨论】: