Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How handle streaming error with 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.

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.

like image 549
Damien Romito Avatar asked Jan 10 '23 11:01

Damien Romito


1 Answers

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

[playerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:NULL];
[self.player replaceCurrentItemWithPlayerItem:playerItem];
like image 134
Leap Bun Avatar answered Jan 20 '23 03:01

Leap Bun