Reputation: 821
Hey,
I do have my App with Tabbar Navigation and everything else in portrait mode where no rotation is supported. Now I have to stream this video, that has to be landscape.
I'm using MPMoviePlayerController which works fine basically, but although it's said to rotate automatically to landscape mode, it stays in portrait mode.
- (IBAction) openFourthInfo:(id)sender{
NSURL *url = [NSURL URLWithString:@"http://my-video.mp4"];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(userPressedDone:)
name:MPMoviePlayerWillExitFullscreenNotification
object:player];
[self.view addSubview:player.view];
[mainView setHidden:YES]; //Need to hide another subview here
player.fullscreen = YES;
[player play];
}
This is how I call the Player. In userPressedDone:
and moviePlaybackComplete:
I basically just set mainView.setHidden = YES;
, remove the observer, remove and release player.
Nothing extraordinary. Any idea why the player stays in portrait though? I tried
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];
It animated a changing status bar, but the view stayed the same. By adding
[[player view] setBounds:CGRectMake(20, 0, 480, 320)];
[[player view] setCenter:CGPointMake(160, 240)];
[[player view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
nothing happens. Replacing player view
with self view
, I just get the parent view to be rotated, not the player view.
Where's the problem and how may I solve it? I'm trying since 5 hours or so -.-
Thank you!
Upvotes: 4
Views: 4006
Reputation: 8488
MPMoviePlayerController no longer works in landscape by default so to make it work in landscape you need to apply a transform to the view.
UIView * playerView = [moviePlayerController view];
[playerView setFrame: CGRectMake(0, 0, 480, 320)];
CGAffineTransform landscapeTransform;
landscapeTransform = CGAffineTransformMakeRotation(90*M_PI/180.0f);
landscapeTransform = CGAffineTransformTranslate(landscapeTransform, 80, 80);
[playerView setTransform: landscapeTransform];
In addition, if you want the regular full screen controls, use the following sample.
moviePlayerController.fullscreen = TRUE;
moviePlayerController.controlStyle = MPMovieControlStyleFullscreen;
Upvotes: 5