在MPMoviePlayerController上调用renderInContext

时间:2010-06-26 17:02:29

标签: objective-c mpmovieplayercontroller

我正在尝试以编程方式从MPMoviePlayerController视频的当前帧中创建图像。我正在使用renderInContext调用播放器的view.layer然而创建的图像全部是黑色的视频播放器控件,但我希望看到视频的当前帧

我的代码(http://pastie.org/1020066

UIGraphicsBeginImageContext(moviePlayer.view.bounds.size);
[moviePlayer.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

// I also tried this code (same results)

// moviePlayer is a subview of videoView (UIView object)
UIGraphicsBeginImageContext(videoView.bounds.size);
[videoView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

1 个答案:

答案 0 :(得分:0)

如果您想获取电影的缩略图,则应该检查MPMoviePlayerController的thumbnailImageAtTime:timeOption:方法。