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];
Embed the player in it's own view controller and implement shouldAutorotateToInterfaceOrientation
as follows:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
Make a sub class of MPMoviePlayerViewController
:
@interface MyMoviePlayerViewController ()
@end
@implementation MyMoviePlayerViewController
- (BOOL)shouldAutorotate { return NO; }
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
@end
精彩评论