【问题标题】:NotificationCenter observer calls plays multiple videos - swift - programmaticallyNotificationCenter 观察者调用播放多个视频 - 快速 - 以编程方式
【发布时间】:2020-12-23 00:16:56
【问题描述】:

我有不同的UIViews 一个在另一个之上;他们每个人都使用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 UIViews start playing as well... 这对我来说很奇怪,因为我将观察者的对象设置为只有 self.player.currentItem

我怎样才能只播放这个AVPlayer

【问题讨论】:

    标签: swift uiview avplayer nsnotificationcenter


    【解决方案1】:

    问题在于这些代码存在于每个视图中。因此,当通知发布时,所有这些视图都是观察者。所以他们都开始玩了。

    【讨论】:

      猜你喜欢
      • 2021-04-07
      • 1970-01-01
      • 1970-01-01
      • 2019-08-22
      • 2020-06-28
      • 2013-03-05
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      相关资源
      最近更新 更多