【问题标题】:MPMoviePlayerViewController not playing in Landscape orientation under 5.1MPMoviePlayerViewController 在 5.1 下不能横向播放
【发布时间】:2012-03-09 01:46:46
【问题描述】:

在 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);
}

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

任何帮助将不胜感激。

【问题讨论】:

  • 我也有同样的问题,不是电影播放器​​,而是普通的视图控制器,它以纵向模式显示,但 shoudlAutorotate 方法在纵向模式下返回 NO,如果您有解决方案,请发布它:)
  • 我还没有找到解决方案。糟糕的是,我创建了一个新项目并设置了这个基本模式,它运行良好。所以...我认为这与我在生产应用程序中设置的视图层次结构有关。这似乎更像是 5.1 的错误,而不是我的代码,因为它自 3.x 以来一直运行良好。

标签: iphone ios mpmovieplayercontroller mpmovieplayer ios5.1


【解决方案1】:

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

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

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

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

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

【讨论】:

    【解决方案2】:

    我在 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 的设备上对我有用。不确定模拟器。

    【讨论】:

      【解决方案3】:

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

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

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

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

      这篇文章帮助我弄清楚了这一点(并且有一些代码): iOS: Disable Autorotation for a Subview

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-16
        • 2013-06-21
        • 1970-01-01
        相关资源
        最近更新 更多