Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 6 MPMoviePlayerViewController and presentMoviePlayerViewControllerAnimated Rotation

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];
like image 330
Mat Avatar asked Nov 30 '22 05:11

Mat


2 Answers

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...

like image 171
Ollie Hirst Avatar answered Dec 06 '22 01:12

Ollie Hirst


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;
}
like image 25
Jon Avatar answered Dec 06 '22 01:12

Jon