这可能是我一个简单的问题,但是如何检测 MPMediaPlayer 在Swift 4中播放的时间?
答案 0 :(得分:1)
您可以使用NSNotificationCenter进行跟踪。
func play(url: NSURL) {
let item = AVPlayerItem(URL: url)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "playerDidFinishPlaying:", name: AVPlayerItemDidPlayToEndTimeNotification, object: item)
let player = AVPlayer(playerItem: item)
player.play()
}
func playerDidFinishPlaying(note: NSNotification) {
// Your code here
}