I am using MPMoviePlayerController to play a movie. The movie starts in portrait mode (as that's the only mode the app uses) and stays there even if the device is rotated. I never explicitly set the shouldAutoRotateetc. function to respond to landscape and portrait because I don't want my views resizing. Is there a way to get the video to re开发者_JS百科spond to portrait and landscape rotations? Any help would be greatly appreciated.
FYI: Here is my code
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"TestMovie" ofType:@"m4v"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
//Listen so we can clean up after the movie is over
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlaybackComplete:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController];
[self.view addSubview:moviePlayerController.view];
[moviePlayerController setFullscreen:YES animated:YES];
[moviePlayerController play];
Hmm. OK. Figured it out a half-hour after I was stumped.
There is apparently now an MPMoviePlayerViewController that handles all that. Here's my new updated code:
MPMoviePlayerViewController *moviePlayerView = [[[MPMoviePlayerViewController alloc] initWithContentURL:videoURL] autorelease];
[self presentMoviePlayerViewControllerAnimated:moviePlayerView];
This will allow it to respond to rotation events, etc. Nice!
精彩评论