AVPlayerItem.loadedTimeRanges 上的 KVO 可能吗?
Apple 文档提到了这一点,但是如何为 AVPlayerItem 的 returnedTimeRanges 属性设置键值观察?该属性是一个不会更改的 NSArray,因此您不能只使用 playerItem addObserver:self forKeyPath:@"loadedTimeRanges ...
或者是否有其他方法可以在发生更改时获取通知或更新?
Apples documentation alludes to it, but how do you set up key-value observation for the loadedTimeRanges property of AVPlayerItem? That property is an NSArray that doesn't change, so you can't just use playerItem addObserver:self forKeyPath:@"loadedTimeRanges ...
Or is there another way to get notifications or updates whenever this changes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
实际上,我使用 KVO 来加载时间范围没有任何问题。也许您只是没有设置正确的选项?以下是对Apple的AVPlayerDemo中的一些代码进行了非常细微的修改,而且它对我来说效果很好。
Actually, I'm using KVO for loadedTimeRanges without any trouble. Maybe you're just not setting the right options? The following is a very slight modification of some of the code in Apple's AVPlayerDemo, and it's working quite nicely for me.
更新到 Swift 4.0 及更高版本:
Update to Swift 4.0 and later:
正确的。 loadTimeRanges 不会改变,但其中的对象会改变。您可以设置一个计时器每秒运行一次(左右)并检查loadedTimeRanges 内的值。然后您就会看到您正在寻找的更改。
Right. loadedTimeRanges doesn't change but the objects inside of it change. You could setup a timer to run every second (or so) and inspect the values inside of loadedTimeRanges. Then you'll see the changes you are looking for.