Simple question I can\'t seem to find an answer to for some reason.
How do you loop AVPlayer in Swift?
numberOfLoops = -1 only works for AVAudioPlayer
<
@Christopher Pickslay's answer updated for Swift 4:
func loopVideo(videoPlayer: AVPlayer) {
NotificationCenter.default.addObserver(forName: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: nil, queue: nil) { notification in
videoPlayer.seek(to: CMTime.zero)
videoPlayer.play()
}
}
But, as I mentioned below his answer, be sure to specify the object as the AVPlayer's player item if you have multiple players.