JiaoZiVideoPlayer 全屏顯示不全
引發原因,
DisplayMetrics outMetrics = new DisplayMetrics(); WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { wm.getDefaultDisplay().getRealMetrics(outMetrics); }else { wm.getDefaultDisplay().getMetrics(outMetrics); }
通過使用獲取螢幕寬高來對全屏ViewGroup設定寬高。導致有的手機底部狀態列可能為透明,螢幕全屏顯示導致覆蓋不全底部狀態列
不建議使用上面錯誤寫法,會導致4.2版本以上的手機直接獲取手機解析度,不考慮是否會有狀態列存在,直接全屏.
正確的方式是應該回去當前app繪製區域
Rect outRect = new Rect(); (JZUtils.scanForActivity(getContext())).findViewById(Window.ID_ANDROID_CONTENT).getDrawingRect(outRect); heightPixel = outRect.height(); widthPixel= outRect.width();
目前下面為個人修改的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(); } }