AVQueuePlayer是否支持异步添加AVPlayerItems?
我有一个视频播放器,需要播放网络上的一系列视频。这些视频的 URL 事先未知,因为它们来自其他 HTTP 请求的 XML 或 JSON 响应。
当视频 URL 已知时,我创建 AVPlayerItems
并将它们添加到 AVQueuePlayer
中。我观察播放器状态和项目状态以确定正在播放哪个项目等。
问题是播放器似乎进入各种奇怪的状态,它返回 AVFoundationErrorDomain 错误 -11800 ,从那时起播放器拒绝播放任何内容。即使在取消分配 AVQueuePlayer 并启动新的播放器后,之前播放的视频仍会拒绝播放。
将新的 AVPlayerItems
添加到正在播放的 AVQueuePlayer
是受支持的操作,还是我应该以其他方式执行此操作?如果支持,我应该注意/做什么(例如线程问题?KVO 问题?)才能使这项工作正常进行?
I have a video player that needs to play a sequence of videos from the network. The URLs for these videos are not known in advance, as they come from XML or JSON responses from other HTTP requests.
As the video URLs become known, I create AVPlayerItems
and add them to an AVQueuePlayer
. I observe the player status and the item status to determine which item is playing etc.
The problem is that the player seems to get into various weird states where it returns AVFoundationErrorDomain error -11800
and from then on the player refuses to play anything. Even after deallocating the AVQueuePlayer
and starting a new one, videos that previously played refuse to play.
Is adding new AVPlayerItems
to a playing AVQueuePlayer
a supported operation, or should I be doing this another way? If it is supported, what should I be looking out for/doing (Eg. thread issues? KVO issues?) to make this work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案是肯定的,
AVQueuePlayer
确实可以异步添加AVPlayerItems
。重要的部分在文档中:由于 KVO 观察者可能会在其他线程上触发,因此从主线程调用
AVPlayer
(和AVQueuePlayer
)上的所有方法至关重要。如果不这样做,当事情进入不一致的状态时,您会看到奇怪的行为和
AVFoundationErrorDomain -11800
The answer is yes,
AVQueuePlayer
does work with addingAVPlayerItems
asynchronously. The important part is in the documentation:Since KVO observers might fire on other threads, it's critical to call all methods on
AVPlayer
(andAVQueuePlayer
) from the main thread.If you don't, you'll see the weird behaviour and
AVFoundationErrorDomain -11800
as things get into inconsistent states