這是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=%@",([email protected]"Loaded":[email protected]"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。
來源
2011-06-23 18:16:31
tba