How do you loop AVPlayer in Swift?

后端 未结 8 2023
后悔当初
后悔当初 2020-12-02 15:15

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

<
8条回答
  •  既然无缘
    2020-12-02 15:47

    @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.

提交回复
热议问题