Search code examples
iosobjective-clandscapeuiinterfaceorientation

Play video fullscreen in landscape mode, when my entire application is in lock in portrait mode


I want to play video in landscape mode in fullscreen. And my application is lock in portrait mode. How to implement this. Please help me. Thanks in advance


Solution

  • I've done this in on of my app. To do this you need to check that is your viewcontroller that where you want to play a video.

    • The first thing you have to do is check Device Orientation to Portrait,Landscape left, Landscape right in your project target

    • In your AppDelegate do the below code

      -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
      
          UIStoryboard *mainStoryboard;
          if (IS_IPHONE) {
              mainStoryboard= [UIStoryboard storyboardWithName:@"Main" bundle: nil];
          }
          else{
             mainStoryboard= [UIStoryboard storyboardWithName:@"Main_iPad" bundle: nil];
          }
      
          ViewControllerThatPlaysVideo *currentViewController=    ViewControllerThatPlaysVideo*)[mainStoryboard     instantiateViewControllerWithIdentifier:@"postDetailView"];
          if(navigationController.visibleViewController isKindOfClass:    [ViewControllerThatPlaysVideo class]]){
             if([currentViewController playerState])
                  return UIInterfaceOrientationMaskLandscape|UIInterfaceOrientationMaskPortrait;
             return UIInterfaceOrientationMaskPortrait;
          }
          return UIInterfaceOrientationMaskPortrait;
      }