carrotzoe
carrotzoe

Reputation: 147

two AVPlayers, how to know which one finished playing

If I have one AVPlayer, I could monitor the AVPlayerItemDidPlayToEndTime. But if I have two AVPlayers, I wouldn't know which one finished. Is there a way to know which finishes?

Upvotes: 0

Views: 62

Answers (1)

Shehata Gamal
Shehata Gamal

Reputation: 100523

You can try

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

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

Upvotes: 2

Related Questions