【问题标题】:HTTP Live Streaming with AVPlayer in iOS 4.0?在 iOS 4.0 中使用 AVPlayer 进行 HTTP 直播?
【发布时间】:2011-09-19 20:45:45
【问题描述】:

是否可以在 iOS 4.0 上使用 HTTP Live Streaming 和 AVPlayer?这显然是 4.0 的一个记录特性。但是,如果我在运行 iOS 4.0.1 的 3GS 上运行 Apple's SitchedStreamPlayer sample code,单击“加载电影”不会播放流,而是会出现错误:

2011-06-21 13:14:49.428 StitchedStreamPlayer[680:307] 由于错误,资产的轨道未加载: 打不开

MPMediaPlayer 可以在同一设备上播放the same stream。但是,我需要 AVPlayer 的有效解决方案。

有谁知道如何让 Apple 的 StichedStreamPlayer 代码在 4.0 上运行?运行时要求说它应该在“iOS 4.0 或更高版本”上运行。

谢谢!

【问题讨论】:

    标签: iphone ios avfoundation avplayer http-live-streaming


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2012-07-23
      • 2012-11-10
      • 1970-01-01
      • 2012-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多