Youtube video not playing in landscape mode in iOS 8

前端 未结 1 866
误落风尘
误落风尘 2020-12-17 02:43

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

相关标签:
1条回答
  • 2020-12-17 03:11

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

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

    Update : Works in iOS 9 as well

    0 讨论(0)
提交回复
热议问题