0

我正在尝试使用集成了 exoplayer 的画中画模式

我能够获得画中画视图,但无法在画中画模式下获得视频的完整视图。

在此处输入图像描述

例如:红色的是视频,当我进入画中画视图时,只有视频的绿色部分可见。

这是我的代码:

 @Override
protected void onUserLeaveHint() {
    super.onUserLeaveHint();

    enterPipMode();
}

private void enterPipMode() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
            && getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) {            
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
           PictureInPictureParams.Builder builder = new PictureInPictureParams.Builder();

            enterPictureInPictureMode(builder.build());
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                enterPictureInPictureMode();
            }
        }
    }
}
4

1 回答 1

0

这就是我PictureInPicture在我的应用程序中实现的方式。

@Override
protected void onUserLeaveHint() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        if (!isInPictureInPictureMode()) {
            Rational rational = new Rational(250, 150); //you can use VideoView getWidth(),getHeight() here 
            builder.setAspectRatio(rational).build();
            enterPictureInPictureMode(builder.build());
        }
    }
}

然后检测用户是否最小化了屏幕

@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
    if (isInPictureInPictureMode) {
        Toast.makeText(this, "in picture in picture mode.", Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(this, "out of picture in picture mode.", Toast.LENGTH_SHORT).show();
    }
}

PictureInPitureParam.Builder在 onCreate() 中初始化

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        builder = new PictureInPictureParams.Builder();
    }
于 2018-10-25T10:05:38.597 回答