I'm kind of lost on this one. I have a class that needs to play audio and video files or streams. It has a completely custom UI so I use AVPlayer for this.
There is one live audio stream that just won't play. Every single time the AVPlayerItem observer triggers AVPlayerItemStatusFailed, the error of AVPlayer is nil.
But when I try to play the same audio stream in MPMoviePlayerController or Safari or Chrome it works just fine. Which is extremely weird since internally MPMoviePlayerController uses AVPlayer.
This is the URL of the live audio stream that fails: http://bit.ly/1gIqjV6
My AVPlayer code (doesn't work with the URL)
_currentItem = [[AVPlayerItem alloc] initWithURL:[NSURL URLWithString:@"http://bit.ly/1gIqjV6"]];
[self startObservingPlayerItem:self.currentItem];
_avPlayer = [[AVPlayer alloc] initWithPlayerItem:self.currentItem];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying:) name:AVPlayerItemDidPlayToEndTimeNotification object:self.currentItem];
The AVPlayerItem observer
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([object isEqual:[self.avPlayer currentItem]])
{
if ([keyPath isEqualToString:@"status"])
{
switch ([self.avPlayer currentItem].status) {
case AVPlayerItemStatusReadyToPlay:
NSLog(@"AVPlayerItemStatusReadyToPlay");
break;
case AVPlayerItemStatusFailed:
// The live audio stream always fails, error is always nil
NSLog(@"AVPlayerItemStatusFailed");
NSError* error = self.avPlayer.error;
break;
case AVPlayerItemStatusUnknown:
NSLog(@"AVPlayerItemStatusUnknown");
break;
}
}
}
}
With MPMoviePlayerController (works fine with the URL)
MPMoviePlayerViewController* controller = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"http://bit.ly/1gIqjV6"]];
[rootViewController presentViewController:controller animated:YES completion:nil];
Has anyone ever encountered an issue like this? Thanks in advance.