How do you loop AVPlayer in Swift?

后端 未结 8 2030
后悔当初
后悔当初 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:43

    Alternatively, you can use the block-based NSNotificationCenter API:

    func loopVideo(videoPlayer: AVPlayer) {
        NSNotificationCenter.defaultCenter().addObserverForName(AVPlayerItemDidPlayToEndTimeNotification, object: nil, queue: nil) { notification in
            videoPlayer.seekToTime(kCMTimeZero)
            videoPlayer.play()
        }
    }
    

提交回复
热议问题