My code was working fine until I upgraded iPhone to iOS 5.0. The MPMoviePlayerViewController used to work fine but it doesn’t work on iOS 5.0 so I have to use MPMoviePlayerController for iOs 5.0 and later versions. It works fine but MPMoviePlayerController doesn’t rotate automatically like it used to do with MPMoviePlayerViewController.
Following is my code. Could anyone please suggest me how to make MPMoviePlayerController code rotate automatically?
-(void)playVideo {
NSString *filePath = [appDelegate filePath:@"startup.mp4"];
if(!appDelegate.iOS5) {
// This works perfectly till iOS 4 versions. Rotates automatically
MPMoviePlayerViewController *videoController = [[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:filePath]] autorelease];
[self presentMoviePlayerViewControllerAnimated:videoController];
} else {
// This doesn't rotate automatically
NSURL *url = [NSURL fileURLWithPath:filePath];
MPMoviePlayerController* moviePlayer = [[[MPMoviePlayerController alloc] initWithContentURL:url] autorelease];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}
Try subclassing MPMoviePlayerController and forcing the orientation to portrait only.
Not the best solution but I guess it should work.