How handle streaming error with AVPlayer

audio-streaming, avplayer, error-handling, key-value-observing, streaming

Solution

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

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

Problem

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.

Original source