I have an AVPlayer and when I get to the end of the duration, I want to go back to the beginning, but I don't want to restart the 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)
}
From here, I can simply .play() the AVPlayer and it will play from the beginning. But, prior to me .play(), the .seek() function does not indicate to the user that it has been reset back to the beginning. The AVPlayer frame does not actually transition back to the first frame until AFTER I execute .play().
Question:
How can I get the AVPlayer to change the actual frame it shows to the user when using the .seek() functionality?