如何处理AVPlayer的流错误 [英] How handle streaming error with AVPlayer

查看:199
本文介绍了如何处理AVPlayer的流错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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的流错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆