No AVPlayer Delegate? How to track when song finished playing? Objective C iPhone development

前端 未结 5 1230
死守一世寂寞
死守一世寂寞 2020-11-27 14:09

I\'ve looked around but I can\'t find a delegate protocol for the AVPlayer class. What gives?

I\'m using its subclass, AVQueuePlayer, to pl

5条回答
  •  时光取名叫无心
    2020-11-27 14:50

    Swift 3 - I add an observer to AVPlayerItem every time I add a video to the player:

    func playVideo(url: URL) {
      let playerItem = AVPlayerItem(asset: AVURLAsset(url: someVideoUrl))
      NotificationCenter.default.addObserver(self, selector: #selector(playerItemDidPlayToEndTime), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: playerItem)
      self.player.replaceCurrentItem(with: playerItem)
      self.player.play()
    }
    
    func playerItemDidPlayToEndTime() {
      // load next video or something
    }
    

提交回复
热议问题