我正在使用 AVPlayer 从 url 播放视频。 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.moviePlayer
更改为 self.moviePlayer.currentItem
。
关于ios - AVPlayerItemDidPlayToEndTimeNotification 未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33871179/