为什么我不能捕获MPMoviePlayerController的屏幕截图? [英] Why can't I capture a screenshot of MPMoviePlayerController?

查看:122
本文介绍了为什么我不能捕获MPMoviePlayerController的屏幕截图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要捕获一个视频播放在mpmovieplayer控制器的屏幕截图,但我得到的是一个红色屏幕(我做了coverView红色背景和0.5 alpha)。

I need to capture a screen shot of a video playing in mpmovieplayer controller, but all I get is a red screen (I made the coverView with red background and 0.5 alpha).

下面是代码:

NSArray *windows = [[UIApplication sharedApplication] windows];
if ([windows count] > 1)
{
    UIWindow *moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];


    UIView *coverView = [[UIView alloc] initWithFrame:moviePlayerWindow.bounds];
    [mainController.moviePlayer pause];  //Without that it won't work either!
    coverView.backgroundColor = [UIColor redColor];
    coverView.alpha = 0.5;
    [moviePlayerWindow addSubview:coverView];

    UIGraphicsBeginImageContext(coverView.bounds.size);
    [coverView.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *screenShot;

    screenShot = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    UIImageWriteToSavedPhotosAlbum(screenShot, self, nil, nil);
}

任何想法

感谢

推荐答案

跟进问题:

最近我有一个项目,需要在这个线程中提出的功能,我很高兴地说,已经有一个苹果提供的解决方案。我发布这样,以便访问此线程的人可以得到一个答案。

Recently I have a project that requires the functionality that was asked in this thread again, and I am glad to say there is already an apple provided solution to this. I am posting this so that people that visit this thread can get an answer.

MPMoviePlayerController现在有一个方法,返回一个UIImage你想捕获的时刻。 p>

MPMoviePlayerController now has a method that return a UIImage of the moment you want to capture.

- (UIImage *)thumbnailImageAtTime:(NSTimeInterval)playbackTime timeOption:(MPMovieTimeOption)option

只要放入要捕获的playbackTime和bingo,UIImage。

Just put in the playbackTime you want to capture, and bingo, UIImage.

看看你的代码,我建议你应该寻找一个替代方法获取图像,而不是从mpmovieplayer本身。原因是您使用的方法是一个私有框架代码,其次,截取视频的截图很容易崩溃。

Looking at your codes, I would like to advise that you should look for an alternative method of getting the image rather than from the mpmovieplayer itself. The reason being that the method you are using is a private framework code, and second, getting screenshots off a video is highly prone to crashes.

而不是获取屏幕截图视频,如何事先标记视频?这些代码很容易被苹果的应用拒绝。

Instead of getting a screenshot from the video, how about tagging the video beforehand? The codes looks highly vulnerable to an app rejection by apple.

这篇关于为什么我不能捕获MPMoviePlayerController的屏幕截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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