Adding an MPMoviePlayerController in full screen mode?
Solution 1
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];
Solution 2
I think the best way to resolve it is using the MPMoviePlayerViewController
instead of the MPMoviePlayerController
.
The MPMoviePlayerViewController
class implements a simple view controller for displaying full-screen movies. Unlike using an MPMoviePlayerController
object on its own to present a movie immediately, you can incorporate a movie player view-controller wherever you would normally use a view-controller.
To present a movie player view controller modally, you typically use the presentMoviePlayerViewControllerAnimated:
method. This method is part of a category on the UIViewController class and is implemented by the Media Player framework
. The presentMoviePlayerViewControllerAnimated:
method presents a movie player view controller using the standard transition animations for presenting video content. To dismiss a modally presented movie player view controller, call the dismissMoviePlayerViewControllerAnimated
method.
rottendevice
Updated on December 31, 2020Comments
-
rottendevice over 3 years
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.
-
rottendevice over 13 yearsThanks! Actually, self.view is not fullscreen. Do you know how I would set the video to be fullscreen?
-
rottendevice over 13 yearsOh wait, I found it.
[moviePlayer setFullscreen:YES animated:YES];
-
rottendevice over 13 yearsOh... wait again! Plugging that line in prevents the video from loading in landscape. Any idea how to do this?
-
mostafa tourad over 13 yearsfake fullscreen: just use the entire screen by e.g. adding that moviePlayer.view directly to the current keyWindow.
-
Raptor over 12 yearsYes, using
MPMoviePlayerViewController
minimizes the need of writing a lot of codes. -
BastiBen over 12 yearsThanks! Brilliant idea to inject the player on the key window.