【问题标题】:MPMoviePlayerController won't change rotation automatically to landscapeMPMoviePlayerController 不会自动将旋转更改为横向
【发布时间】:2011-09-06 09:29:00
【问题描述】:

嘿,
我的应用程序确实带有标签栏导航,其他所有东西都处于不支持旋转的纵向模式。现在我必须播放这个视频,它必须是横向的。 我使用的是 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)]; 

什么都没有发生。用self view 替换player view,我只是让父视图旋转,而不是播放器视图。

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

【问题讨论】:

    标签: iphone objective-c video orientation


    【解决方案1】:

    默认情况下,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;
    

    【讨论】:

    • 感谢您的快速回复,这对您有帮助!但是就像那样“完成”按钮消失了,所以没有机会中止电影..我该如何取回它?
    • @Nareille - 更新了答案。
    • 再次感谢! moviePlayerController.fullscreen = TRUE; 将打破它,显示 mainView,并且不要旋转视图,将其排除在外,效果很好!谢谢!
    • 如果不和其他语言结合,那么应该是moviePlayerController.fullscreen = YES;
    猜你喜欢
    • 1970-01-01
    • 2010-10-21
    • 1970-01-01
    • 2020-01-29
    • 1970-01-01
    • 2016-08-25
    • 2012-06-14
    相关资源
    最近更新 更多