我正在尝试使用集成了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();
}
}
}
}
答案 0 :(得分: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();
}
}
在onCreate()中初始化PictureInPitureParam.Builder
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
builder = new PictureInPictureParams.Builder();
}