How to detect when AVPlayer video ends playing?

前端 未结 10 919
感动是毒
感动是毒 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:28

    Swift 3.0

    let videoPlayer = AVPlayer(URL: url)
    
    NotificationCenter.default.addObserver(self, selector:#selector(self.playerDidFinishPlaying(note:)),name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem)
    
    @objc func playerDidFinishPlaying(note: NSNotification){
            print("Video Finished")
        }
    

提交回复
热议问题