2011-06-21 164 views
3

是否可以在iOS 4.0上使用AVPlayer的HTTP Live Streaming?這顯然是4.0的記錄特徵。但是,如果我跑Apple's SitchedStreamPlayer sample code我的3GS運行iOS 4.0.1,點擊「加載電影」不打流,而是給出了一個錯誤:在iOS 4.0中使用AVPlayer進行HTTP實時流式傳輸?

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或更高版本」。

謝謝!

回答

5

這是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

相關問題