两个AVPlayers,如何知道哪个完成了播放

时间:2019-03-07 20:12:43

标签: swift avplayer

如果我有一个AVPlayer,则可以监视AVPlayerItemDidPlayToEndTime。但是,如果我有两个AVPlayers,我将不知道哪个完成了。有没有办法知道哪个完成?

1 个答案:

答案 0 :(得分:2)

您可以尝试

@objc func playerDidFinishPlaying( _ sender: Notification) {
   if let _ = sender.object as? Player1 {
   }
}

NotificationCenter.default.addObserver(self, selector: #selector(playerDidFinishPlaying(_:)) , name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: nil)