MPMoviePlayerController不会自动将旋转更改为横向

时间:2011-06-01 15:02:08

标签: iphone objective-c video orientation

嘿,
我的应用程序有Tabbar导航和其他所有在纵向模式下不支持旋转。现在我必须播放这个必须是风景的视频。 我正在使用MPMoviePlayerController基本上工作正常,但据说它自动旋转到横向模式,它仍处于纵向模式。

- (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];
}

这就是我给玩家打电话的方式。在userPressedDone:moviePlaybackComplete:我基本上只设置mainView.setHidden = YES;,删除观察者,删除并释放播放器。

没什么特别的。知道为什么玩家会留在肖像中吗? 我试过了

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES]; 

它为更改状态栏设置了动画,但视图保持不变。添加

[[player view] setBounds:CGRectMake(20, 0, 480, 320)];
[[player view] setCenter:CGPointMake(160, 240)];
[[player view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)]; 
没有任何反应。用player view替换self view,我只是让父视图旋转,而不是播放器视图。

问题在哪里,我该如何解决?我正在尝试5个小时左右-.-
谢谢!

1 个答案:

答案 0 :(得分:5)

默认情况下,MPMoviePlayerController不再在横向上工作,因此要使其在横向中工作,您需要将变换应​​用于视图。

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];

此外,如果您需要常规全屏控制,请使用以下示例。

moviePlayerController.fullscreen = TRUE;
moviePlayerController.controlStyle = MPMovieControlStyleFullscreen;