4

In previous iOS versions, our video would rotate automatically but in iOS 6 this is no longer the case. I know that the presentMoviePlayerViewControllerAnimated was designed to do that before but how can I tell the MPMoviePlayerViewController to rotate automatically?

MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
pnuts
  • 58,317
  • 11
  • 87
  • 139
Mat
  • 223
  • 3
  • 9
  • Possible dup to http://stackoverflow.com/questions/12526054/autorotate-in-ios-6-has-strange-behaviour. Actually that question and answers talks about this problem well. – James Chen Sep 26 '12 at 02:43

3 Answers3

10

In appdelegate.m :

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    if ([[self.window.subviews.lastObject class].description isEqualToString:@"MPMovieView"]) {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    else {
        return UIInterfaceOrientationMaskPortrait;
    }
}

Kinda a hack, but works well...

Ollie Hirst
  • 592
  • 2
  • 6
  • 14
  • *sidenote:* this is for iOS 6+ . For iOS 5 or below, use codes similar to `UIInterfaceOrientationPortrait` – Raptor Jul 24 '13 at 13:16
  • When I start a movie I get back as an description; 'UITransitionView' Why is this? it's the same name as my view controllers are returning – directory Oct 05 '14 at 20:53
6

I just ran into the same problem. James Chen's solution is correct, but I ended up doing something a little simpler that also works - overriding application:supportedInterfaceOrientationsForWindow in my app delegate and returning allButUpsideDown if my rootView controller was modally presenting an MPMoviePlayerViewController. Admittedly a hack, and may not be appropriate to all situations, but saved me having to change all my view controllers:

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return [rootViewController.modalViewController isKindOfClass:MPMoviePlayerViewController.class ] ? UIInterfaceOrientationMaskAll : UIInterfaceOrientationMaskAllButUpsideDown;
}
Pochi
  • 13,391
  • 3
  • 64
  • 104
Jon
  • 462
  • 5
  • 14
  • Hi Jon, first thanks for answering. You have solved my same MPMoviePlayerViewController rotation issue But while i dissmiss the moviePlayer, still i am getting MPMoviePlayerViewController in rootViewController.modalViewController. I tried : [self dismissModalViewControllerAnimated:YES]; and [movieController dismissMoviePlayerViewControllerAnimated]; – Kirti Nikam Aug 26 '13 at 07:22
4

This is not limited to MPMoviePlayerViewController. From iOS 6 the autorotation has been changed. see Autorotate in iOS 6 has strange behaviour .

To make your app behave as pre-iOS 6, you have to make the app support all orientations (edit UISupportedInterfaceOrientations in plist), then for all other view controllers which don't support rotation, override this method to return NO:

- (BOOL)shouldAutorotate {
    return NO;
}

By default MPMoviePlayerViewController supports all orientations so this should be enough to make it work.

Community
  • 1
  • 1
James Chen
  • 10,794
  • 1
  • 41
  • 38
  • I changed my plist file to allow all orientations yet it affects nothing. My app still remains in portrait mode no matter the orientation. I searched high and low through code to see if something is blocking rotation but I see nothing. Any ideas. – Mat Sep 26 '12 at 14:25
  • @JamesChen this is it! so simple, saved me hours digging! – CdB Feb 07 '13 at 13:40