ios – AVPlayerItemDidPlayToEndTimeNotification未触发

我正在使用AVPlayer从网址播放视频. AVPlayerItemDidPlayToEndTimeNotification未触发.我已经把断点检查了.以下是我的代码片段: –
@IBAction func playButtonClicked(sender: UIButton) {
    let url:NSURL = NSURL(string: self.currentSelectedContent.link)!
    moviePlayer = AVPlayer(URL: url)
    playerViewController = AVPlayerViewController()
    playerViewController.player = moviePlayer

    self.presentViewController(playerViewController,animated: true) {
        NSNotificationCenter.defaultCenter().addObserver(self,selector: "moviePlayBackFinished",name: AVPlayerItemDidPlayToEndTimeNotification,object: self.moviePlayer)
        self.playerViewController.player?.play()
    }

}

func moviePlayBackFinished() {
    self.playerViewController.dismissViewControllerAnimated(true,completion: nil)
}

解决方法

根据文档,观察对象必须是AVPlayerItem实例,而不是AVPlayer本身.尝试将self.movi​​ePlayer更改为self.movi​​ePlayer.currentItem.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...