25
votes

Since iOS 3.2 the MPMoviePlayerController class allows to embed a movie in the view hierarchy. Now I'm facing this issue: I create my portrait view by placing an instance of MPMoviePlayerController. When the user touch the "fullscreen" button this view enters in fullscreen mode but the view remains in portrait. When the user rotates the device the fullscreen movie view is not auto-rotated as my app forbids landscape interface orientation. So in order to allow auto-rotation of movie player fullscreen view, I changed my view controller shouldAutorotateToInterfaceOrientation: method to return YES for landscape if - and only if - the movie player is in full screen mode. This works perfectly: when the user enters in full screen and then rotates to landscape the player is auto-rotated to landscape and fills the entire screen.

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    //return (interfaceOrientation == UIInterfaceOrientationPortrait);
    if(UIInterfaceOrientationIsPortrait(interfaceOrientation)) {
        return(YES);
    }

    if(UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
        return([movieController isFullscreen]);
    }

return(NO);
}

Now the issue arises when I touch the "Done" button in the full screen view while remaining in landscape. The full screen closes and then what I see is my original view autorotated: but I don't want this auto-rotation.

A partial, but not acceptable solution, is to listen for "MPMoviePlayerDidExitFullscreenNotification" and, if the interface is rotated to landscape, force re-orientation to using the undocumented and private function:

[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait]

This works but is not acceptable as usage of this method is forbidden.

I tried to force orientation using [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait] but as I'm in a Tab Bar this doesn't work (the UITabBar remains Landscape-sized).

Thanks for your help

2
Have you find a solution ? I'm in the same situation and I can't find a solution.klefevre
In theory with the new way introduced in iOS6 to manage orientation this problem can be fixed by setting each view controller orientation directly. This can be done using the new methods that ask to each view controller for orientation permissions.viggio24

2 Answers

2
votes

You can use a separate view controller for MPMovieplayer. You don't have to override the

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

in the original view controller.

if you are using MPMoviePlayerViewController, everything is already set nicely for you, as the method shouldAutorotateToInterfaceOrientation: will return YES by default. You can use it as a subview or present it modally by calling
presentMoviePlayerViewControllerAnimated: