iOS 4.0中使用AVPlayer进行HTTP实时流媒体播放?

4
有没有可能在iOS 4.0上使用AVPlayer进行HTTP Live Streaming?这显然是4.0的一个记录功能。但是,如果我在运行iOS 4.0.1的3GS上运行Apple's SitchedStreamPlayer示例代码,点击“Load Movie”不会播放流,而会出现错误:

2011-06-21 13:14:49.428 StitchedStreamPlayer[680:307] 由于错误而未加载资产的轨道: 无法打开

MPMediaPlayer能够在同一设备上播放相同的流。但是,我需要一个可以使用AVPlayer的可行解决方案。

有人知道如何使Apple的StichedStreamPlayer代码在4.0上工作吗?运行时要求说它应该在“iOS 4.0或更高版本”上工作。

谢谢!

1个回答

6

这是4.0版本中的一个bug,但我找到了一种解决方法。以下是使用AVPlayer加载视频的正确方式:

    AVPlayer *player = [AVPlayer playerWithURL:[NSURL URLWithString:@"http://qtdevseed.apple.com/addemo/ad.m3u8"]];
// now use KVO to decide when it's ready to play
// works in both 4.3 and 4.0.1

StitchedStreamPlayer的代码在4.3中能运行,但在4.0.1中不能。

AVURLAsset *asset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:@"http://qtdevseed.apple.com/addemo/ad.m3u8"] options:nil];
    NSArray *tracksKeys = [NSArray arrayWithObjects:kTracksKey, kDurationKey, kPlayableKey, nil];
    [asset loadValuesAsynchronouslyForKeys:tracksKeys completionHandler:
     ^{
         NSError *error = nil;
         AVKeyValueStatus status = [asset statusOfValueForKey:[tracksKeys objectAtIndex:0] error:&error];
         NSLog(@"status=%@,error=%@",(status==AVKeyValueStatusLoaded?@"Loaded":status==AVKeyValueStatusFailed?@"Failed":@"?!"),error);
     }];

// output in 4.3: status=Loaded,error=(null)
// output in 4.0.1:  status=Failed,error=Error Domain=AVFoundationErrorDomain Code=-11828 "Cannot Open" UserInfo=0x15f2a0 {NSLocalizedFailureReason=This media format is not supported., NSUnderlyingError=0x1599e0 "The operation couldn’t be completed. (OSStatus error -12847.)", NSLocalizedDescription=Cannot Open}

更多信息请参见StitchedStreamPlayer的旧版本


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接