Adding MPMoviePlayerController in full screen?

I have a UIButton in an iPhone app that plays a movie when I click on it. The code for playing the movie is as follows:

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 would like the movie to open in full screen mode, like all movies did before the iOS 3.2 update, where the blue β€œFinish” button was in the upper left corner and the video played in landscape mode by default.

Does anyone know how to do this? Thanks.

+8
objective-c iphone ios4 mpmovieplayercontroller
source share
2 answers

Assuming self.view uses full 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 do not want to use the current self.view, but just work in full-screen mode (I call it: fake-fullscreen, since it does not call the full-screen 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]; 
+17
source share

I think the best way to solve it is to use MPMoviePlayerViewController instead of MPMoviePlayerController .

The MPMoviePlayerViewController class implements a simple view controller for displaying full-screen movies. Unlike using the MPMoviePlayerController object to immediately present a movie, you can enable the video player viewer wherever you normally use a view controller.

To present the video player view controller in a fashionable way, you usually use the presentMoviePlayerViewControllerAnimated: method. This method is part of the category in the UIViewController class and is implemented by the Media Player framework . The presentMoviePlayerViewControllerAnimated: method is a video player view controller using standard transition animations to represent video content. To reject a modally presented movie view controller, call the dismissMoviePlayerViewControllerAnimated method.

+11
source share

All Articles