如何处理AVPlayer的流错误

编程入门 行业动态 更新时间:2024-10-26 01:27:19
本文介绍了如何处理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的流错误

本文发布于:2023-11-25 14:18:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630095.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何处理   错误   AVPlayer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!