views:

407

answers:

3

Hi guys,

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).

Here is the code:

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);
}

Any ideas???

Thanks

+2  A: 

I was curious about his myself. I believe there are similar issues with taking screenshots of OpenGL stuff too.

If you look at this blog post http://getsetgames.com/2009/07/30/5-ways-to-take-screenshots-of-your-iphone-app/, they have a method that works for an EAGLView, it might be worth giving it a go for your issue.

lyonanderson
I don't think it has to do with opengl
Alex1987
+1  A: 

Hi Alex,

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.

wahkiz
Obviously I added the pause method just to experiment. Any examples on "tagging the video" with iphone sdk? Thanks.
Alex1987
A: 

Sounds like you're taking a shot of the video overlay mask http://en.wikipedia.org/wiki/Hardware%5Foverlay

Mobs
Thanks. But still you can capture screenshots of videos as well by pressing the home and power buttons, so maybe there is still a way
Alex1987