ios - 检测 AVQueuePlayer 中的视频项目何时更改
问题描述
在我的项目中,我使用 AVQueuePlayer 播放多个视频,在某些情况下,我想知道当前项目何时完成以及下一个项目何时开始。我像这样使用通知:
NotificationCenter.default.addObserver(self, selector: #selector(self.goToStepTwo), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: self.player?.currentItem)
但此方法仅适用于第一项。
谢谢
解决方案
使用
.addObserver(self, selector: #selector(self.goToStepTwo), name: .AVPlayerItemDidPlayToEndTime, object: self.player?.currentItem)
您明确要求在self.player?.currentItem
播放到最后时收到通知。
要收到任何项目的通知,只需nil
用作object
.addObserver(self, selector: #selector(self.goToStepTwo), name: .AVPlayerItemDidPlayToEndTime, object: nil)
来自https://developer.apple.com/documentation/foundation/notificationcenter/1411723-addobserver
obj
观察者想要接收其通知的对象;也就是说,只有这个发送者发送的通知才会传递给观察者。
如果通过
nil
,通知中心不会使用通知的发送者来决定是否将其传递给观察者。
推荐阅读
- python - while-loop 无法停止(可能会出现我没有意识到的其他问题)
- javascript - CSS Toggle Switch 将类添加到具有本地存储的 DIV
- sql - ASP.NET 和 SQL Server:使用动态值更新最后一条记录
- amazon-web-services - AWS WAF 不阻止来自被阻止 IP 的流量
- javascript - 从流中检索音轨的名称
- javascript - 三元运算符在状态更改时无法按预期工作
- ruby - 通过 Ruby 安装 Cocoapods 会导致错误
- node.js - Heroku postgresql 查询不在 Heroku 上工作,但在本地工作
- javascript - Leaflet API Overlaying 下拉菜单
- c# - 为什么 Assembly.GetTypes() 会触发 AppDomain.CurrentDomain.AssemblyResolve 事件?