我正在调整我的应用程序到Swift 3,我遇到了这个问题.这曾经在Swift 2.2上运行,但现在已经坏了.moviePlayBackFinished永远不会被调用.我尝试以多种方式添加观察者,但都没有成功.
NotificationCenter.default.addObserver(self, selector: #selector(self.moviePlayBackFinished(_:)),
name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem);
NotificationCenter.default.addObserver(self, selector: #selector(moviePlayBackFinished(_:)),
name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem);
NotificationCenter.default.addObserver(self, selector: #selector(self.moviePlayBackFinished(sender:)),
name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem);
// (...)
@objc func moviePlayBackFinished(sender : AnyObject) {
print("playbackFinished");
let zeroCM : CMTime = CMTime(seconds: 0, preferredTimescale: 1000000000);
playerLayer.player?.seek(to: zeroCM);
}
@objc func moviePlayBackFinished(_ notification: Notification) {
print("playbackFinished");
let zeroCM : CMTime = CMTime(seconds: 0, preferredTimescale: 1000000000);
playerLayer.player?.seek(to: zeroCM);
}
Run Code Online (Sandbox Code Playgroud)
任何想法都会受到关注.
谢谢