Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Youtube video not playing in landscape mode in 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.

my code:

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

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

like image 438
Pankaj Wadhwa Avatar asked Sep 22 '14 06:09

Pankaj Wadhwa


1 Answers

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

like image 123
Pankaj Wadhwa Avatar answered Oct 05 '22 12:10

Pankaj Wadhwa