video 满屏显示_JiaoZiVideoPlayer 全屏显示不全

引发原因

int widthPixel;

int heightPixel;

DisplayMetrics outMetrics = new DisplayMetrics();

WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);

wm.getDefaultDisplay().getMetrics(outMetrics);

heightPixel = outMetrics.heightPixels;

widthPixel = outMetrics.widthPixels;

通过使用获取屏幕宽高来对全屏ViewGroup设置宽高。导致有的手机底部状态栏可能为透明,屏幕全屏显示导致覆盖不全底部状态栏

出现下面这个图片问题

小米6X

然后把代码修改为 获取屏幕实际分辨率,不管状态栏高度

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {

wm.getDefaultDisplay().getRealMetrics(outMetrics);

}else {

wm.getDefaultDisplay().getMetrics(outMetrics);

}

看起小米6X是没问题了,但是使用华为Mate9,发现底部导航栏把屏幕给遮盖了

如图

小米6X

华为Mate9

最后如何避免由于底部状态栏导致屏幕全屏显示问题。那么就是获取应用在屏幕中的实际分辨率

获取当前app绘制区域

Rect outRect = new Rect();

(JZUtils.scanForActivity(getContext())).findViewById(Window.ID_ANDROID_CONTENT).getDrawingRect(outRect);

heightPixel = outRect.height();

widthPixel = outRect.width();

应用在分屏的情况下全屏也是ok的

如图

分屏

这个方式获取屏幕高度发现没有问题了,但有一个小缺陷

—–如果在全屏情况下,手动控制底部导航栏显示隐藏,就会导致全屏显示不完全或者遮盖问题。

—–如果不是全屏情况下,手动控制底部导航栏显示隐藏则不会出现这种问题。

目前下面为个人修改的JiaoZiVideoPlayer全屏显示代码

public void startWindowFullscreen() {

Log.i(TAG, "startWindowFullscreen " + " [" + this.hashCode() + "] ");

hideSupportActionBar(getContext());

ViewGroup vp = (JZUtils.scanForActivity(getContext()))//.getWindow().getDecorView();

.findViewById(Window.ID_ANDROID_CONTENT);

View old = vp.findViewById(R.id.jz_fullscreen_id);

if (old != null) {

vp.removeView(old);

}

textureViewContainer.removeView(JZMediaManager.textureView);

try {

Constructor constructor = (Constructor) JZVideoPlayer.this.getClass().getConstructor(Context.class);

JZVideoPlayer jzVideoPlayer = constructor.newInstance(getContext());

jzVideoPlayer.setId(R.id.jz_fullscreen_id);

int widthPixel;

int heightPixel;

// 用户绘制区域

Rect outRect = new Rect();

(JZUtils.scanForActivity(getContext())).findViewById(Window.ID_ANDROID_CONTENT).getDrawingRect(outRect);

heightPixel = outRect.height();

widthPixel = outRect.width();

LayoutParams lp = new LayoutParams(heightPixel, widthPixel);

lp.setMargins((widthPixel - heightPixel) / 2, -(widthPixel - heightPixel) / 2, 0, 0);

// FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(

// ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

vp.addView(jzVideoPlayer, lp);

// jzVideoPlayer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION

// | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN);

jzVideoPlayer.setUp(dataSourceObjects, currentUrlMapIndex, JZVideoPlayerStandard.SCREEN_WINDOW_FULLSCREEN, objects);

jzVideoPlayer.setState(currentState);

jzVideoPlayer.addTextureView();

JZVideoPlayerManager.setSecondFloor(jzVideoPlayer);

final Animation ra = AnimationUtils.loadAnimation(getContext(), R.anim.start_fullscreen);

jzVideoPlayer.setAnimation(ra);

jzVideoPlayer.setRotation(90);

JZUtils.setRequestedOrientation(getContext(), SCREEN_ORIENTATION_PORTRAIT);//强制横屏显示

onStateNormal();

jzVideoPlayer.progressBar.setSecondaryProgress(progressBar.getSecondaryProgress());

jzVideoPlayer.startProgressTimer();

CLICK_QUIT_FULLSCREEN_TIME = System.currentTimeMillis();

} catch (Exception e) {

e.printStackTrace();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值