MPMoviePlayerController thumbnailImageAtTime:timeOption: simple case doesn't work

前提是你 提交于 2020-01-06 20:09:52

问题


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;

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];

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.


回答1:


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.

EDIT:

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=The operation is not supported for this media.

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.



来源:https://stackoverflow.com/questions/11496757/mpmovieplayercontroller-thumbnailimageattimetimeoption-simple-case-doesnt-wor

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