私は速いアプリケーションでいくつかのビデオを再生する必要があります。ビデオは完璧に動作していますが、ビデオが終了した時点を検出したいと思います。私がそれについて調べたところ、NotificationCenter
がその解決策であることが判明しました。このコードを使用しましたが、ビデオの最後にアプリケーションがクラッシュします。スイフト:ビデオの終了を検出
これは私のコードです:
func playVideo(url: NSURL){
let player = AVPlayer(url: url as URL)
NotificationCenter.default.addObserver(self, selector: Selector(("playerDidFinishPlaying")), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem)
player.play()
}
func playerDidFinishPlaying(note: NSNotification) {
print("Video Finished")
}
エラーは次のとおりです。
[myApp.myViewController playerDidFinishPlaying]: unrecognized selector sent to instance 0x79669740
任意のヘルプしてください?
詳細をお知らせください。 –
'url:NSURL'や' func playerDidFinishPlaying(注: 'Swift 2.のようなコードです。Swift 3にコードを書く必要があります。今すぐSwift 2とSwift 3が混在しています。 – matt