Android JWPlayer 全屏显示方向更改并保留视频

标签 android orientation fullscreen jwplayer

我正在使用 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);
        }
    }
}

这对我有用。

关于Android JWPlayer 全屏显示方向更改并保留视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41691185/

相关文章:

java - 如何确保我的线程/进程在不同的内核上运行

iPhone UIActionSheet 自动旋转不起作用

iOS viewWillTransitionToSize 和设备方向

Android 全屏主题不工作

java - 如何在 Android 中将按钮状态保存到 SharedPreferences 中

android - Material SearchView 实现错误

ios - 约束在横向方向上没有按预期工作

android - 全屏自定义对话框?

java - 不同分辨率下的全屏 Swing 应用

android - onCreateView() 等待 AsyncTask 执行?