在竖屏项目中,如何让MPMoviePlayerController全屏播放横屏视频?

3

在我的应用程序中,我只在项目设置中选择了纵向模式:

enter image description here

并且我以这种方式使用它:

player = [[MPMoviePlayerController alloc] init];
[player setContentURL:videoURL];
[player play];

但是,当我使用MPMoviePlayerController在全屏状态下显示视频,并尝试旋转时,它不会旋转,仍停留在portrait模式。有没有简单的方法,在不启用项目设置中的landscape模式的情况下,在全屏状态下激活landscape模式?


我认为你应该尝试使用customMoviePlayer。 - D-eptdeveloper
1个回答

4

您有2个选项:

  1. 在项目设置中启用横屏模式,并覆盖视图控制器的supportedInterfaceOrientations
  2. 在您的应用程序委托中,添加application:supportedInterfaceOrientationsForWindow:方法,并在播放电影时确保返回UIInterfaceOrientationMaskAllButUpsideDown

你能为选项2举个例子吗?播放电影时,我必须在AppDelegate中更改方法还是在ViewController中更改? - Piero
2
应用代理。在您的应用代理中,您可以侦听 MPMoviePlayerWillEnterFullscreenNotification 来启用横向旋转,并侦听 MPMoviePlayerWillExitFullscreenNotification 来禁用它。 - Guy Kogus
谢谢!这是完美的解决方案。 - passwind
@GuyKogus 我正在尝试在Swift中实现这个解决方案,当我尝试在didFinishLaunchingWithOptions中添加NSNotificationCenter.defaultCenter().addObserver(self, selector: "supportedInterfaceOrientationsForWindow:", name: MPMoviePlayerDidEnterFullscreenNotification, object: nil)时,它会抛出未解析的标识符MPMoviePlayerDidEnterFullscreenNotification。你能帮我吗? - Penkey Suresh
你在文件顶部调用了 import MediaPlayer 吗? - Guy Kogus

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接