Search code examples
androidandroid-youtube-api

Full-screen goes out when switching to portrait


I am using Youtube API for android app and I'm looking for a way to avoid exiting full-screen mode while switching between landscape modes. Meaning, I don't want to exit full-screen mode while switching the phone to portrait mode. I need the video to always be on full-screen.

Is there a way to make it happen?

My current code for full screen is:

@Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider,
            YouTubePlayer player, boolean wasRestored) {
        if (!wasRestored) {
            Intent intent = getIntent();
            String Video_Link = intent.getStringExtra("youtube_id");
            player.cueVideo(Video_Link);
            player.setFullscreen(true);
        }
    }

Thanks a lot in advance.


Solution

  • 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...

    otherwise you might try overriding the onconfigchange 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
                    }
        }