JiaoZiVideoPlayer 全屏显示不全

视频 GitHub地址 https://github.com/lipangit/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设置宽高。导致有的手机底部状态栏可能为透明,屏幕全屏显示导致覆盖不全底部状态栏
出现下面这个图片问题

《JiaoZiVideoPlayer 全屏显示不全》 小米6X

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

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
  wm.getDefaultDisplay().getRealMetrics(outMetrics);
}else {
  wm.getDefaultDisplay().getMetrics(outMetrics);
}

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

《JiaoZiVideoPlayer 全屏显示不全》 小米6X

《JiaoZiVideoPlayer 全屏显示不全》 华为Mate9

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

获取当前app绘制区域

Rect outRect = new Rect();
(JZUtils.scanForActivity(getContext())).findViewById(Window.ID_ANDROID_CONTENT).getDrawingRect(outRect);
heightPixel = outRect.height();
widthPixel  = outRect.width();

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

《JiaoZiVideoPlayer 全屏显示不全》 分屏

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

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

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

目前下面为个人修改的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<JZVideoPlayer> constructor = (Constructor<JZVideoPlayer>) 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();
        }

    }
    原文作者:Ready_I
    原文地址: https://www.jianshu.com/p/1dbef8e69711
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞