2

5.1 中是否有任何更改会影响MPMoviePlayerViewController在设备方向方面的工作方式?

我今天开始收到用户报告说视频仅以纵向模式播放。我发现他们使用的是 5.1,我迅速升级了一个设备来重现这种情况。我的代码没有改变并且在 4.x、5.0 和 5.01 中完美运行。

我的应用程序中的所有视图都以纵向模式显示,除非用户单击视频,否则电影播放器​​应该会占据整个屏幕并更多地进入横向模式。该应用使用 5.0 SDK 但面向 4.0。这是我用来显示视频的代码:

VideoPlayer *vp = [[VideoPlayer alloc] initWithContentURL:movieURL];
vp.moviePlayer.movieSourceType = src;
vp.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
vp.moviePlayer.shouldAutoplay = TRUE;
[self presentMoviePlayerViewControllerAnimated:vp];

VideoPlayerMPMoviePlayerViewController的子类,其中shouldAutorotateToInterfaceOrientation被覆盖,如下所示:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIDeviceOrientationLandscapeLeft);
}

整个 Internet 甚至 Apple 都推荐这种模式。我不明白为什么它不能在 iOS 5.1 下运行,或者为什么没有更多人对此抱怨。

任何帮助将不胜感激。

4

3 回答 3

2

我也遇到了同样的问题-我在opengl子视图上播放电影,(我在横向模式下制作交互式电子书,所以需要我的电影-(在uiview中)也可以横向播放)

我通过以下方式纠正了这个问题: 将打开的 glview 子类化为 *viewcontroller 然后将该 *viewcontroller 链接到窗口

因此,在使用时,cocos2d我现在可以以正确的方向使用所有 uikit。将所有 uikit 视图发送到我的子类 opengl 视图。(同时确保添加我的应用程序委托并检查 plist 中是否也说明了方向。)

"#if GAME_AUTOROTATION == kGameAutorotationUIViewController
    [director setDeviceOrientation:kCCDeviceOrientationPortrait];
"#else
    [director setDeviceOrientation:kCCDeviceOrientationLandscapeRight];
"#endif

希望这对某人有帮助:) 我在 cocos2d 很新,所以花了一段时间才弄清楚我做错了什么。

于 2012-05-16T09:03:08.057 回答
1

我在 iOS 5 中遇到了同样的问题。我能够让它工作的唯一方法是继承 MPMoviePlayerViewController。

@implementation MovieViewController

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        return UIInterfaceOrientationIsLandscape(interfaceOrientation);
    } else {
        return UIInterfaceOrientationIsPortrait(interfaceOrientation);
    }
} 
@end

看起来您已经尝试过这样做,但是这段代码在装有 iOS 5.1 的设备上为我工作。不确定模拟器。

于 2012-03-09T02:09:08.560 回答
0

升级到 iOS 5.1 后,我遇到了很多方向问题。对我来说,这是因为链上同级视图控制器的允许方向导致我正在添加的模态控制器没有允许的方向。

您的视图层次结构中是否有将两个子视图添加到视图的情况?我在 applicationDidFinishLaunching 的窗口中添加了两个子视图,在 iOS 5.1 之前,它们可以有独立的允许方向。即,我可以将一个固定在纵向,而顶部的一个旋转。现在,另一个子视图坚持纵向。

我的解决方案是强制下面的非旋转视图:

[self.window insertSubview:self.nonRotatingViewController.view belowSubview:self.rotatingViewController.view];

这篇文章帮助我弄清楚了这一点(并且有一些代码): iOS:禁用子视图的自动旋转

于 2012-03-13T06:20:03.950 回答