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


小米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<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();
        }

    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 5. 图像(Graphics) 5.1 应用图标(App Icon) 5.2 自定义图标(Custom Icons...
    70dd80205ba0阅读 964评论 0 7
  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 13,815评论 1 92
  • 一、导航栏(Navigation Bars) 导航栏出现在app屏幕的顶部,状态栏之下,它能实现在一系列有层级的a...
    Tu_卫佳阅读 1,371评论 2 5
  • 来简书其实时间不算太久,但之前在知乎、贴吧泡了很久,一直有在上面写写的冲动,因为我之前就一直就喜欢写写写的习惯。心...
    若丝阅读 150评论 0 0
  • 早上起床。弟弟感冒了。耽误了我去晨读。我有点儿不开心。我是想去成晨读。可弟弟不舒服,在那里闹。妈妈说下次一定要去晨读。
    付琳越阅读 177评论 0 0