ios - Youtube 视频无法在 iOS 8 中以横向模式播放

标签 ios iphone video youtube ios8

我的应用程序包含以横向和纵向模式播放视频的功能。视频可以是 youtube,在 iOS 7 之前一切正常,但现在 youtube 视频在 iOS 8 上无法以横向模式工作。

我的代码:

- (NSUInteger)application:(UIApplication *)applicationsupportedInterfaceOrientationsForWindow:(UIWindow *)window {


  if ([[window.rootViewController presentedViewController]
     isKindOfClass:[MPMoviePlayerViewController class]] || [[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(@"MPInlineVideoFullscreenViewController")])        {

      return UIInterfaceOrientationMaskAllButUpsideDown;
  } else {

      if ([[window.rootViewController presentedViewController]
         isKindOfClass:[UINavigationController class]]) {

          // look for it inside UINavigationController
          UINavigationController *nc = (UINavigationController *)[window.rootViewController presentedViewController];

          // is at the top?
          if ([nc.topViewController isKindOfClass:[MPMoviePlayerViewController class]]) {
            return UIInterfaceOrientationMaskAllButUpsideDown;

            // or it's presented from the top?
          } else if ([[nc.topViewController presentedViewController]
                    isKindOfClass:[MPMoviePlayerViewController class]]) {
              return UIInterfaceOrientationMaskAllButUpsideDown;
          }
      }
  } 

  return UIInterfaceOrientationMaskPortrait;
}

在 iOS 7 之前一切正常,但在 iOS 8 上停止工作。 任何帮助表示赞赏

最佳答案

虽然回答自己的问题有时很愚蠢,但有助于帮助面临同样问题的其他人。

在 iOS 8 中,我们需要检查 AVFullScreenViewController 而不是检查 MPInlineVideoFullscreenViewController。下面是适用于所有 iOS 版本(即 iOS 8 及更低版本)的完整方法。

 - (NSUInteger)application:(UIApplication *)applicationsupportedInterfaceOrientationsForWindow:(UIWindow *)window {

  if ([[window.rootViewController presentedViewController]
     isKindOfClass:[MPMoviePlayerViewController class]] || [[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(@"MPInlineVideoFullscreenViewController")] || [[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(@"AVFullScreenViewController")]) {

      return UIInterfaceOrientationMaskAllButUpsideDown;
  }else {

      if ([[window.rootViewController presentedViewController]
         isKindOfClass:[UINavigationController class]]) {

          // look for it inside UINavigationController
          UINavigationController *nc = (UINavigationController *)[window.rootViewController presentedViewController];

          // is at the top?
          if ([nc.topViewController isKindOfClass:[MPMoviePlayerViewController class]]) {
              return UIInterfaceOrientationMaskAllButUpsideDown;

              // or it's presented from the top?
          } else if ([[nc.topViewController presentedViewController]
                    isKindOfClass:[MPMoviePlayerViewController class]]) {
              return UIInterfaceOrientationMaskAllButUpsideDown;
          }
      }
  }

  return UIInterfaceOrientationMaskPortrait;
}

更新: 也适用于 iOS 9

关于ios - Youtube 视频无法在 iOS 8 中以横向模式播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25967615/

相关文章:

ios - 在电影文件上使用 GPUImageLookupFilter 会产生黑屏

objective-c - Objective C 中的多播委托(delegate)

video - 保护 Flash 视频不被下载/权利保护

html - 无法在 IE 11 中播放视频

objective-c - 无法读取 kABPersonPhoneProperty

ios - JSON解析奇数节点

iphone - ASIHTTPRequest-从相机胶卷上传文件

video - 使用ffmpeg将WMV转换为mp4获取黑屏

ios - 撰写推文连接应用程序或授权网络不执行任何操作

ios - Ad-Hoc 分布式应用程序未安装在设备上