How to detect when AVPlayer video ends playing?

前端 未结 10 956
感动是毒
感动是毒 2020-11-28 07:48

I\'am using AVPlayer for playing local video file (mp4) in Swift. Does anyone know how to detect when video finish with playing? Thanks

10条回答
  •  悲哀的现实
    2020-11-28 08:14

    Swift 3.0

    let videoPlayer = AVPlayer(URL: url)
    NotificationCenter.default.addObserver(self, selector:#selector(self.playerDidFinishPlaying(note:)),name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem)
    
    func playerDidFinishPlaying(note: NSNotification){
        //Called when player finished playing
    }
    

提交回复
热议问题