0

Portrait mode videos can be played full screen in portrait orientation with the YouTube app, is this possible to achieve with the youtube player api in android?

This is what I am referring to: http://thenextweb.com/apps/2015/07/22/you-can-now-watch-vertical-videos-in-full-screen-on-youtubes-android-app/

donny.rewq
  • 621
  • 1
  • 7
  • 21

1 Answers1

6

You can see in this SO answer the solution on how to retain the full-screen mode even if the phone is in portrait mode.

On an orientation change, the onCreate method is called. You could try adding this line within the Activity in question in your Manifest file to prevent the onCreate call.

android:configChanges="orientation|keyboardHidden|screenSize|layoutDirection"

and it might maintain the fullscreen status of youtube for you.

You can also try overriding the onConfigurationChanged method:

@Override //reconfigure display properties on screen rotation
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

            //Checks the orientation of the screen
            if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) 
                {
                // handle change here
                } 
            else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
                {
                // or here
                }
    }

You can also read this documentation:

Flag for setFullscreenControlFlags(int) to enable automatic control of the orientation.

The behavior is to force landscape orientation when entering fullscreen and switching back to the original orientation setting when leaving fullscreen. The implementation will also exit fullscreen automatically when the device is rotated back to portrait orientation. This should generally be set unless the application is locked in landscape orientation or you require fullscreen in portrait orientation.

Hope this helps!

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59
  • 3
    Thank you for your help. I did try to override the onConfigurationChanged but it didn't work on its own. Because the FULLSCREEN_FLAG_CONTROL_ORIENTATION flag is set on default. So you have to remove that bit by simply setting: setFullscreenControlFlags(FULLSCREEN_FLAG_CONTROL_SYSTEM_UI); And if the video is uploaded to youtube in portrait mode, it will be shown in portrait mode when entering full screen. – donny.rewq Sep 17 '16 at 02:57
  • @donny.rewq... saved my day. I was digging all morning, but your answer hit's the spot. Thanks :) – Gal Rom Jan 29 '17 at 08:24
  • it's that easy to achieve the same behavior of official YouTube app: https://stackoverflow.com/questions/53242972/youtubeplayer-going-fullscreen-from-portrait-phone-orientation-can-easily-get-o – user924 Nov 24 '18 at 09:59
  • `The implementation will also exit fullscreen automatically when the device is rotated back to portrait orientation` and it is a big problem here - when it forces landscape orientation after pressing fullscreen button it can leave that fullscreen mode instantly (because you physically hold the phone in portrait orientation) if you don't rotate your phone fast to the landscape orientation physically. – user924 Nov 24 '18 at 10:01