MPMoviePlayerController 不会自动将旋转更改为横向
嘿,
我的应用程序带有标签栏导航,其他所有内容都处于纵向模式,不支持旋转。现在我必须流式传输这段视频,而且必须是横向的。 我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,MPMoviePlayerController 不再在横向模式下工作,因此要使其在横向模式下工作,您需要对视图应用变换。
此外,如果您想要常规的全屏控件,请使用以下示例。
MPMoviePlayerController no longer works in landscape by default so to make it work in landscape you need to apply a transform to the view.
In addition, if you want the regular full screen controls, use the following sample.