DrDani
DrDani

Reputation: 45

Force MPMoviePlayerController to play in landscape

I'm new to iPhone Development and writing my first App. The whole App only needs portrait mode, except for playing movies. I am using MPMoviePlayerController to start the movie and it plays in protrait mode. How can I force MPMoviePlayerController to play all movies in Landscape. I am using Xcode 4 and building for iOS 4.0+. Do I need to enter some settings in the info.plist to allow MPMoviePlayerController to play in landscape?

Here is the code I use to initialize MPMoviePlayerController:

MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL: url]; 
[self.view addSubview:theMovie.view];
theMovie.allowsAirPlay=YES;
[theMovie setFullscreen:YES animated:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie];
[theMovie play]; 

Upvotes: 4

Views: 4006

Answers (2)

Sam Xu
Sam Xu

Reputation: 272

Make a sub class of MPMoviePlayerViewController:

@interface MyMoviePlayerViewController ()

@end

@implementation MyMoviePlayerViewController

- (BOOL)shouldAutorotate { return NO; }
- (NSUInteger)supportedInterfaceOrientations {
  return UIInterfaceOrientationMaskLandscape;
}

@end

Upvotes: 0

Nick Weaver
Nick Weaver

Reputation: 47241

Embed the player in it's own view controller and implement shouldAutorotateToInterfaceOrientation as follows:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}

Upvotes: 6

Related Questions