我使用AVPlayer来流式跟踪。我想要处理所有错误,如网络不可用或流不可用但我发现任何这种错误的处理程序。
I use AVPlayer to stream tracks.I'm trying to handle all errors like network unavailable or stream unaivalable But I find any handler for this kind of error.
我已经为avplayer的状态添加了一个KVO。
I've already added a KVO for on the avplayer's status.
[self.player addObserver:self forKeyPath:@"status" options:0 context:nil];但即使流不存在(例如:错误的url),状态切换到AVPlayerStatusReadyToPlay。
But even the stream doesn't exist (example: wrong url), the status switch to AVPlayerStatusReadyToPlay.
编辑
解决方案是使用AVPLayerItems并使用AVQueuPlayer。另一个问题是我在每个轨道上重新分配了这个播放器。
Solution was to work with AVPLayerItems and use AVQueuPlayer. The other problem was I reallocated this player at every tracks.
推荐答案将KVO添加到AVPlayerItem,而不是使用NSKeyValueObservingOptionNew的AVPlayer。 / p>
Add KVO to AVPlayerItem instead of AVPlayer with NSKeyValueObservingOptionNew as well.
[playerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:NULL]; [self.player replaceCurrentItemWithPlayerItem:playerItem];更多推荐
如何处理AVPlayer的流错误
发布评论