HTTP Live Streaming with AVPlayer in iOS 4.0?

不想你离开。 提交于 2019-12-18 02:58:09

问题


Is it possible to use HTTP Live Streaming with AVPlayer on iOS 4.0? This was clearly a documented feature of 4.0. However, if I run Apple's SitchedStreamPlayer sample code on my 3GS running iOS 4.0.1, clicking "Load Movie" does not play the stream, but gives an error:

2011-06-21 13:14:49.428 StitchedStreamPlayer[680:307] The asset's tracks were not loaded due to an error: Cannot Open

MPMediaPlayer is able to play the same stream on the same device. However, I need a working solution with AVPlayer.

Does anyone know how to get Apple's StichedStreamPlayer code to work on 4.0? The Runtime Requirements say it should work on "iOS 4.0 or later".

Thanks!


回答1:


This is a bug in 4.0, but I found a workaround. Here is the correct way to load video with 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

 

The code from StitchedStreamPlayer works in 4.3 but not 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}

 

For more info see the old version of StitchedStreamPlayer.



来源:https://stackoverflow.com/questions/6431517/http-live-streaming-with-avplayer-in-ios-4-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!