swift. AVPlayer. How to track when song finished playing?

前端 未结 7 586
春和景丽
春和景丽 2021-01-30 13:51

What is the east way to track when song finished playing with AVPlayer in Swift?

Is there any function which is called when avplayer finished playing, or I should combin

相关标签:
7条回答
  • 2021-01-30 14:51

    For Swif3 you will need to change as follow:

    func play(url: NSURL) {
    let item = AVPlayerItem(URL: url)
      NotificationCenter.default.addObserver(self,selector:Selector("playerDidFinishPlaying"), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: item)
    
    let player = AVPlayer(playerItem: item)
    player.play() 
    }
    
    func playerDidFinishPlaying() {
    // Your code here
    } 
    
    0 讨论(0)
提交回复
热议问题