Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play landscape video with MPMovieViewController in a portrait-only app

My app's supported interface orientations are Portrait and Upside down. However, when a video is played, I want it to play full screen landscape. Currently with this code, it only plays portrait, even when the device is rotated:

[player.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
player.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self presentMoviePlayerViewControllerAnimated:player];

How can I force it into landscape mode?

like image 722
soleil Avatar asked Oct 22 '12 23:10

soleil


1 Answers

Here is how I do it:
In the project file, make sure you are supporting the Landscape Orientations supported interface orientations
Now in all of your ViewControllers that should still be Portrait Only, add this code

//ios6
- (BOOL)shouldAutorotate {
    return NO;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

//ios4 and ios5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

I have put in both the iOS5 and iOS6 calls so that my code will run on both.

When your MPMoviePlayerController view becomes fullscreen, it will be a new ViewController layered on top of everything else. So, it will be allowed to rotate according to the Supported Interface Orientations of the Project. It will not see where you forced the other ViewControllers into Portrait.

like image 70
Walter Avatar answered Sep 28 '22 20:09

Walter