开发者

My iPhone Video Only Plays in Portrait Mode

开发者 https://www.devze.com 2023-02-08 14:51 出处:网络
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

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!

0

精彩评论

暂无评论...
验证码 换一张
取 消