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

发布于 2024-11-11 16:13:58 字数 1781 浏览 3 评论 0原文

嘿,
我的应用程序带有标签栏导航,其他所有内容都处于纵向模式,不支持旋转。现在我必须流式传输这段视频,而且必须是横向的。 我正在使用 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)]; 

什么也不会发生。用自身视图替换播放器视图,我只是旋转父视图,而不是播放器视图。

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

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风启觞 2024-11-18 16:13:58

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

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文