在iOS 4.0中使用AVPlayer进行HTTP直播 [英] HTTP Live Streaming with AVPlayer in iOS 4.0?

查看:1138
本文介绍了在iOS 4.0中使用AVPlayer进行HTTP直播的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在iOS 4.0上使用带有AVPlayer的HTTP Live Streaming?这显然是4.0的记录功能。但是,如果我运行 Apple's运行iOS 4.0.1的3GS上的SitchedStreamPlayer示例代码,单击加载电影不会播放流,但会出错:

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]由于错误,未加载资产的曲目:
无法打开

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

MPMediaPlayer可以播放相同的流相同的设备。但是,我需要一个使用AVPlayer的工作解决方案。

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

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

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".

谢谢!

推荐答案

这是4.0中的一个错误,但我找到了一个解决方法。以下是使用AVPlayer加载视频的正确方法:

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

 

StitchedStreamPlayer的代码工作在4.3但不是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}

 

有关详细信息,请参阅旧版本的StitchedStreamPlayer

For more info see the old version of StitchedStreamPlayer.

这篇关于在iOS 4.0中使用AVPlayer进行HTTP直播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆