是否可以在 iOS 4.0 上使用 AVPlayer 进行 HTTP 直播?这显然是 4.0 的记录功能。但是,如果我运行 Apple's SitchedStreamPlayer sample code在我运行 iOS 4.0.1 的 3GS 上,单击“加载电影”不播放流,但给出错误:
2011-06-21 13:14:49.428 StitchedStreamPlayer[680:307] The asset's tracks were not loaded due to an error: Cannot Open
MPMediaPlayer 可以播放 the same stream在同一台设备上。但是,我需要一个适用于 AVPlayer 的解决方案。
有谁知道如何让 Apple 的 StichedStreamPlayer 代码在 4.0 上运行?运行时要求说它应该在“iOS 4.0 或更高版本”上运行。
谢谢!
最佳答案
这是 4.0 中的错误,但我找到了解决方法。以下是使用 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}
有关详细信息,请参阅 the old version of StitchedStreamPlayer .
关于iphone - 在 iOS 4.0 中使用 AVPlayer 进行 HTTP 直播?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6431517/