How handle streaming error with AVPlayer

亡梦爱人 提交于 2019-12-07 10:45:17

问题


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.

I've already added a KVO for on the avplayer's status.

 [self.player addObserver:self forKeyPath:@"status" options:0 context:nil];

But even the stream doesn't exist (example: wrong url), the status switch to AVPlayerStatusReadyToPlay.

EDIT

Solution was to work with AVPLayerItems and use AVQueuPlayer. The other problem was I reallocated this player at every tracks.


回答1:


Add KVO to AVPlayerItem instead of AVPlayer with NSKeyValueObservingOptionNew as well.

[playerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:NULL];
[self.player replaceCurrentItemWithPlayerItem:playerItem];



回答2:


There is a notification you shall subscribe

[nc addObserver:self selector:@selector(_itemDidError:) name:AVPlayerItemNewErrorLogEntryNotification object:_playerItem];

But that won't solve all the problem. I see it will not fire in the case like 404



来源:https://stackoverflow.com/questions/24004313/how-handle-streaming-error-with-avplayer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!