Play videos fullscreen in landscape (iPhone)
I have an app that is built as a hierarchy of viewControllers.
On of the view Controllers is for a 'video section' of the app.
The app is designed to be portrait only, however, I want to force the videos to play fullscreen in landscape (just like the iPod app on the iPhone).
After searching around, I see that many people have this problem.
I finally have been able to rotate it, but it doesn't work in full screen, that defaults to portrait.
And since it doesn't work in full screen, you see elements in the parent views over the video.
Is there an easy way to rotate this video in full screen, or do I have to broadcast a message to the parent views to hide elements when the video is playing?
here is the code:
NSURL *url = [NSURL URLWithString:[recipeData objectForKey:@"videoPath"]];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
// Register to receive a notification when the movie has finished playing. 开发者_Python百科
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
moviePlayer.shouldAutoplay = YES;
moviePlayer.view.frame = [[UIScreen mainScreen] applicationFrame];
moviePlayer.view.transform = CGAffineTransformMakeRotation(1.57079633);
moviePlayer.view.bounds = CGRectMake(0.0, 0.0, 480, 320);
[self.view addSubview:moviePlayer.view];
//commenting out the line below will rotate the video, leaving it uncommented forces it to play fullscreen in portrait
[moviePlayer setFullscreen:YES animated:NO];
I put the method to create the video in the appDelegate and target it whenever the video is launched. This did the trick, keeping it above everything else.
Have you tried using MPMoviePlayerViewController
instead? it presents a full screen almost modal view Controller to handle the video playing. I use it in >=3.2 version and use a hacked up version of MPMoviePlayerController
for <3.2
For full screen playback you should use MPMoviePlayerViewController and then to make it launch and play in landscape format use the "shouldAutorotateToInterfaceOrientation" method on the MPMoviePlayerViewController class.
Looks like this:
[yourInstanceOfMPMoviePlayerViewController shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeRight];
精彩评论