Search code examples
androidorientationfullscreenjwplayer

Android JWPlayer fullscreen on Orientation Changed And Retain Video


I am using JWPlayer So Try to Retain Video And FullScreen On Orietation Changed

my code is :

@Override
protected void onDestroy() {
    Log.i(UIH.TAG_SCR, "Is Rotated : " + isRotated);
    if(!isRotated) {
        playerView.stop();
    } else {
        isRotated = false;
    }
    super.onDestroy();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    Log.i(UIH.TAG_SCR, "ORIENTATION : " + newConfig.orientation);
    if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
        isRotated = true;
        Log.i(UIH.TAG_SCR, "ORIENTATION : PORTRAIT");
    } else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        isRotated = true;
        Log.i(UIH.TAG_SCR, "ORIENTATION : LANDSCAPE");
        playerView.setFullscreen(true, true);
    }
    super.onConfigurationChanged(newConfig);
}

But it doesn't works!

LogCat is :

I/SCREEN_TAG: ORIENTATION : 1

I/SCREEN_TAG: ORIENTATION : PORTRAIT

I/SCREEN_TAG: Is Rotated : true

I/SCREEN_TAG: ORIENTATION : 2

I/SCREEN_TAG: ORIENTATION : LANDSCAPE

I/SCREEN_TAG: Is Rotated : true


Solution

  • Try this :

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
            if(playerView.getFullscreen()) {
                playerView.setFullscreen(false, true);
            }
        } else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            if(!playerView.getFullscreen()) {
                playerView.setFullscreen(true, true);
            }
        }
    }
    

    It works to me.