Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 737
Monika Patel Avatar asked Apr 21 '16 04:04

Monika Patel


People also ask

Can you force an app into landscape mode?

When on the main screen, under the orientation section, you will see a number of options like 'Auto-rotate OFF', 'Auto-rotate ON', 'Forced Portrait' and 'Forced Landscape'. As the names suggest, you can use these buttons as one-tap shortcuts to toggle the orientation of your device.

How do I lock an app to landscape?

On the main screen of Rotation Manager, select an orientation by tapping on either the vertical or horizontal icons next to a specific app to lock it into either landscape or portrait mode. Highlighting both icons will allow that particular app to auto-rotate.


2 Answers

Simplest solution in swift 3 Add this to your app delegate:

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
    if window == self.window {
        return .portrait
    } else {
        return .allButUpsideDown
    }
}
like image 103
Eyzuky Avatar answered Oct 11 '22 16:10

Eyzuky


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;
    }
    
like image 32
Pratik Jamariya Avatar answered Oct 11 '22 17:10

Pratik Jamariya