Reputation: 958
I have different UIView
s one on top of the other; each of them plays a video using AVPlayer
I need each video to be replayed at the end and in order to do so I use this code:
NotificationCenter.default.addObserver(self, selector: #selector(playerDidReachEnd), name: .AVPlayerItemDidPlayToEndTime, object: self.player.currentItem)
@objc fileprivate func playerDidReachEnd(){
self.player.seek(to: .zero)
self.player.play()
}
I noticed that when the selector is called, all the other players in the other UIView
s start playing as well...
This is strange to me because I've set the object of the observer to be only the self.player.currentItem
How can I make only this AVPlayer
play?
Upvotes: 0
Views: 114
Reputation: 534925
The problem is that that code is in every one of those views. So when the notification is posted, all of those views are observers. So they all start playing.
Upvotes: 1