Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayerViewController | Allow landscape mode

I'm trying to stream a video in my app. The method I've found is :

NSURL *theMovieURL = [NSURL URLWithString:self.data.trailer];
        if (theMovieURL)
        {
            self.movieController = [[MPMoviePlayerViewController alloc] initWithContentURL:theMovieURL];
            [self presentMoviePlayerViewControllerAnimated:self.movieController];
            [self.movieController.moviePlayer play];
        }

I'm not sure if it's the most conventional, but it works.

The problem is that I can't figure out how to allow the landscape mode, for the video only. Should I use something like shouldAutorotate or shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation , and how ?

FYI, the entire app allows only the portrait mode.

Thanks for your help.

like image 979
Nicolas Roy Avatar asked Jun 24 '13 13:06

Nicolas Roy


People also ask

How do I change from portrait to landscape mode?

Change orientation of whole document To change the orientation of the whole document, select Layout > Orientation. Choose Portrait or Landscape.

How do I force all apps in landscape mode?

Setting the app upWhen on the main screen, under the orientation section, you will see a number of options like 'Auto-rotate OFF', 'Auto-rotate ON', 'Forced Portrait' and 'Forced Landscape'. As the names suggest, you can use these buttons as one-tap shortcuts to toggle the orientation of your device.


1 Answers

shouldAutoRotate is deprecated as of iOS 6 and should be avoided unless you're going for < 6 .

Instead, you'd want to override the supportedInterfaceOrientations and preferredInterfaceOrientationForPresentation methods.

In this case, if you don't want to subclass the media player you could override a method in the app delegate like so:

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if ([[self.window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]])
    {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    else
    {
        return UIInterfaceOrientationMaskPortrait;
    }
}
like image 69
Justin Ermer Avatar answered Nov 04 '22 21:11

Justin Ermer