2
votes

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.

1

1 Answers

1
votes

It looks like it's your m3u8 playlist from here. I tried a blank project with a simple AVPlayer, and while the test stream ("http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"), as well as the 'hi' and 'lo' streams from your m3u8 file worked, creating the AVPlayerItem with your m3u8 file always failed.

The diff in the m3u8 is as follows:

Yours:

#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=35200, CODECS="mp4a.40.2"

Apple's sample:

#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=200000

Do you have any other m3u8 playlists to test?