Android JWPlayer 全屏方向改变并保留视频

Android JWPlayer fullscreen on Orientation Changed And Retain Video

我正在使用 JWPlayer,因此尝试在更改方向时保留视频和全屏

我的代码是:

@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);
}

但是不行!

LogCat 是:

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

试试这个:

@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);
        }
    }
}

对我有用。