ios – AVPlayerItemDidPlayToEndTimeNotification未触发

前端之家收集整理的这篇文章主要介绍了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相关文章