如何解决在iOS 4.0中使用AVPlayer进行HTTP实时流传输?
| 在iOS 4.0上可以将HTTP Live Streaming与AVPlayer一起使用吗?这显然是4.0的记录功能。但是,如果我在运行iOS 4.0.1的3GS上运行Apple的SitchedStreamPlayer示例代码,则单击“加载电影”不会播放流,但会出现错误: 2011-06-21 13:14:49.428 StitchedStreamPlayer [680:307]由于错误,资产的曲目未加载: 打不开 MPMediaPlayer能够在同一设备上播放相同的流。但是,我需要使用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}
有关更多信息,请参见旧版本的StitchedStreamPlayer。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。