问题
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