MPMoviePlayerController thumbnailImageAtTime:timeOption:简单案例不起作用 [英] MPMoviePlayerController thumbnailImageAtTime:timeOption: simple case doesn't work

查看:295
本文介绍了MPMoviePlayerController thumbnailImageAtTime:timeOption:简单案例不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我像这样构建电影播放器​​...

I build the movie player like this ...

    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
    player.view.frame = myView.bounds;
    player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [player prepareToPlay];

    [myView addSubview:player.view];
    self.mp = player;

URL指向m3u8网络流.很好玩.然后我要一张这样的图片...

The url points to an m3u8 web stream. It plays just fine. Then I ask for an image like this ...

NSTimeInterval currentInterval = self.mp.currentPlaybackTime;
UIImage *image = [self.mp thumbnailImageAtTime:currentInterval timeOption:MPMovieTimeOptionExact];

我尝试将currentInterval备份一秒钟.我尝试了两个时间选项(精确和关键帧),但是图像始终为零.知道为什么吗?谢谢.

I've tried backing the currentInterval up by one second. I've tried both time options (exact and keyframe), but image is always nil. Any idea why? Thanks.

推荐答案

我的理解是,MPMoviePlayerController缩略图方法不适用于HTTP Live Streaming(HLS)流.仅用于文件.不幸的是,尽管我在过去几周内看到或阅读过该书,但我找不到关于它的权威参考.我自己也有同样的经历.

My understanding is that the MPMoviePlayerController thumbnail methods don't work for HTTP Live Streaming (HLS) streams; only for files. Unfortunately I can't find an authoritative reference for that, although I saw, or read, it somewhere in the last couple of weeks. I've also had the same experience, myself.

也就是说,可能可以使用

That said, it might be possible to generate thumbnails for an HLS stream using AVAssetImageGenerator.

我刚刚针对常规HTTP文件和通过HLS访问的同一文件测试了AVAssetImageGenerator.它能够从HTTP缩略图生成缩略图,但是对于HLS缩略图,AVAssetImageGenerator返回以下错误:

I've just tested AVAssetImageGenerator against a regular HTTP file, and the same file accessed over HLS. It was able to generate a thumbnail from the HTTP one, but the for the HLS one, AVAssetImageGenerator returned the following error:

NSLocalizedFailureReason =该媒体不支持该操作.

NSLocalizedFailureReason=The operation is not supported for this media.

因此,总而言之,HTTP Live Streaming似乎不支持创建缩略图.如果情况允许,您也许可以在服务器上生成缩略图,将其作为Web服务使用,然后从客户端中的服务器请求它们.

So, in summary, it looks as though HTTP Live Streaming doesn't support creating thumbnails. If your situation allows, you may be able to generate thumbnails on the server, make them available as a web service, then request them from the server in the client.

这篇关于MPMoviePlayerController thumbnailImageAtTime:timeOption:简单案例不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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