[英]NotificationCenter observer calls plays multiple videos - swift - programmatically
I have different UIView
s one on top of the other;我有不同的
UIView
一个在另一个之上; 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:他们每个人都使用
AVPlayer
播放视频我需要在最后重播每个视频,为此我使用以下代码:
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
我注意到,当调用选择器时,其他
UIView
中的所有其他玩家也开始播放......这对我来说很奇怪,因为我已经将观察者的 object 设置为只有self.player.currentItem
How can I make only this AVPlayer
play?我怎样才能只播放这个
AVPlayer
?
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.
于是他们都开始玩了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.