首页 文章

m3u8音频流在MPMoviePlayerController中播放但不在AVPlayer中播放?

提问于
浏览
2

我有点迷失在这一点上 . 我有一个类需要播放音频和视频文件或流 . 它有一个完全自定义的UI,所以我使用AVPlayer .

有一个现场音频流不会播放 . 每次AVPlayerItem观察者触发AVPlayerItemStatusFailed时,AVPlayer的错误都是零 .

但是当我尝试在MPMoviePlayerController或Safari或Chrome中播放相同的音频流时,它工作得很好 . 这是非常奇怪的,因为内部MPMoviePlayerController使用AVPlayer .

这是失败的实时音频流的URL:http://bit.ly/1gIqjV6

我的AVPlayer代码(不适用于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];

AVPlayerItem观察者

-(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;
            }
        }
    }
}

使用MPMoviePlayerController(适用于URL)

MPMoviePlayerViewController* controller = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"http://bit.ly/1gIqjV6"]];
[rootViewController presentViewController:controller animated:YES completion:nil];

有没有人遇到过像这样的问题?提前致谢 .

1 回答

  • 1

    看起来这是你的m3u8播放列表 . 我尝试了一个带有简单AVPlayer的空白项目,当测试流(“http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8”)以及m3u8文件中的'hi'和'lo'流工作时,使用m3u8文件创建AVPlayerItem总是失败 .

    m3u8中的差异如下:

    你:

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

    Apple的样本:

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

    你还有其他m3u8播放列表需要测试吗?

相关问题