我正在使用 Exoplayer2 使用 hls url 流式传输视频,完成活动以在单击返回或单击主页按钮时进入画中画模式。我想向下拖动 exoplayer 视图进入画中画模式或向下拖动 exoplayer 视图以像画中画类型那样缩放它。
在该视频屏幕中还有其他视图,例如视频的详细信息。当我拖动 exoplayer 视图时,缩放 exoplayer 视频并淡入淡出以隐藏详细信息视图。
画中画代码
private void pictureInPictureMode() {
if (supportsPiPMode() && getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
Rational aspectRatio = new Rational(playerView.getWidth(), playerView.getHeight());
pictureInPictureParamsBuilder.setAspectRatio(aspectRatio).build();
if (canEnterPiPMode()) enterPictureInPictureMode(pictureInPictureParamsBuilder.build());
}
}
@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
inPIP = isInPictureInPictureMode;
if (isInPictureInPictureMode) {
landscapeViews();
bottomAdv.setVisibility(View.GONE);
} else {
portraitViews();
}
}
@Override
protected void onUserLeaveHint() {
pictureInPictureMode();
}
private boolean canEnterPiPMode() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
return (AppOpsManager.MODE_ALLOWED == appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_PICTURE_IN_PICTURE, Process.myUid(), getPackageName()));
}
return false;
}
public boolean supportsPiPMode() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
}
指导我改进我的代码。