Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding an MPMoviePlayerController in full screen mode?

I have a UIButton in my iPhone app that, when clicked, plays a movie. The code to play the movie looks like this:

NSURL *url = [[NSBundle mainBundle] URLForResource:@"Robot" withExtension:@"m4v"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.controlStyle = MPMovieControlModeDefault;
[moviePlayer.view setFrame: self.view.bounds];
[self.view addSubview: moviePlayer.view];
[moviePlayer play];

I'd like the movie to open in full screen mode, the way that all movies did prior to the iOS 3.2 update, where the blue "Done" button was in the top left corner, and the video played in landscape mode by default.

Does anyone know how to do this? Thanks.

like image 360
rottendevice Avatar asked Mar 22 '11 19:03

rottendevice


1 Answers

Assuming that self.view is using the entire screen:

NSURL *url = [[NSBundle mainBundle] URLForResource:@"Robot" withExtension:@"m4v"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
moviePlayer.view.transform = CGAffineTransformConcat(moviePlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2));
[moviePlayer.view setFrame: self.view.bounds];
[self.view addSubview: moviePlayer.view];
[moviePlayer play];

Now assuming that you basically dont want to use the current self.view but simply have it working in fullscreen (I call this; fake-fullscreen as it does not invoke the fullscreen-property);

NSURL *url = [[NSBundle mainBundle] URLForResource:@"Robot" withExtension:@"m4v"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
moviePlayer.view.transform = CGAffineTransformConcat(moviePlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2));
UIWindow *backgroundWindow = [[UIApplication sharedApplication] keyWindow];
[moviePlayer.view setFrame:backgroundWindow.frame];
[backgroundWindow addSubview:moviePlayer.view];
[moviePlayer play];
like image 167
Till Avatar answered Nov 09 '22 23:11

Till