我有点迷失在这一点上。我有一个类需要播放音频和视频文件或流。它有一个完全自定义的UI,所以我使用AVPlayer。
有一个现场音频流无法播放。每次AVPlayerItem观察者触发AVPlayerItemStatusFailed时,AVPlayer的错误都是零。
但是当我尝试在MPMoviePlayerController或Safari或Chrome中播放相同的音频流时,它可以正常工作。这是非常奇怪的,因为内部MPMoviePlayerController使用AVPlayer。
这是失败的实时音频流的网址:http://bit.ly/1gIqjV6
我的AVPlayer代码(不适用于网址)
_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];
有没有人遇到过这样的问题? 提前谢谢。
答案 0 :(得分: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播放列表需要测试吗?