iOS 4.0 中使用 AVPlayer 进行 HTTP 直播?

发布于 2024-11-16 13:08:41 字数 654 浏览 3 评论 0原文

是否可以在 iOS 4.0 上通过 AVPlayer 使用 HTTP 直播?这显然是 4.0 的已记录功能。但是,如果我运行 Apple SitchedStreamPlayer 示例代码在我的运行 iOS 4.0.1 的 3GS 上,单击“加载电影”不会播放流,但会出现错误:

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

MPMediaPlayer 能够在同一设备上播放同一流。但是,我需要 AVPlayer 的工作解决方案。

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

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

此生挚爱伱 2024-11-23 13:08:41

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

    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

以下是使用AVPlayer

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}

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文