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

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

它为不断变化的状态栏设置动画,但 View 保持不变。通过添加

[[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,我只是让父 View 旋转,而不是播放器 View 。

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

最佳答案

默认情况下,MPMoviePlayerController 不再在横向模式下工作,因此要使其在横向模式下工作,您需要对 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];

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

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

关于iphone - MPMoviePlayerController 不会自动将旋转更改为横向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6203320/

相关文章:

objective-c - 自动更正通知

objective-c - NSSortDescriptor 具有名字和姓氏,或者具有名字或姓氏?

iphone - 在 View Controller 中加载 TableView 时出现问题

iphone - 如何使用 WkWebView 内联播放视频

css - 使用 mediaelements 定位小型设备

ios - Segue 不将数据传递给 ViewController

iphone - 替换NSString中的字符列表

iphone - for..... 循环中的加速

iphone - 如何检查字符串中的某些字符?

.net - 在 WPF MediaElement 中显示视频的第一帧