Youtube 视频无法在 iOS 8 中以横向模式播放 [英] Youtube video not playing in landscape mode in iOS 8

查看:119
本文介绍了Youtube 视频无法在 iOS 8 中以横向模式播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用包含以横向和纵向模式播放视频的功能.视频可以是 youtube 也可以在 iOS 7 之前一切正常,但现在 youtube 视频在 iOS 8 上无法在横向模式下运行.

My app consist a functionality of playing videos both in landscape and portrait mode.videos can be youtube also everything was working fine till iOS 7 but now youtube videos are not working in landscape mode on 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 上停止工作.任何帮助表示赞赏

Everything was working fine till iOS 7 but stop working on iOS 8. Any help appreciated

推荐答案

回答你自己的问题有时很愚蠢,但帮助其他面临同样问题的人很好.

Well its sometimes silly to answer your own question but its good to help others who are facing the same problem.

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

in iOS 8 instead of checking for MPInlineVideoFullscreenViewController we need to check for AVFullScreenViewController. So below is the complete method for all iOS versions i.e iOS 8 and less.

 - (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

这篇关于Youtube 视频无法在 iOS 8 中以横向模式播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆