WebView 視訊全屏播放(基於Html5 video)

賞金術士發表於2020-11-30

參考:WebView 支援 Html5 video 進行全屏播放

主要方法: onShowCustomView() onHideCustomView()

       @Override  //全屏時呼叫
        public void onShowCustomView(View view, CustomViewCallback callback) {
            super.onShowCustomView(view, callback);
            Log.d("MyInfo","onShowCustomView...");
            if (mCustomView != null) {
                callback.onCustomViewHidden();
                return;
            }
            mCustomView=view;
            mCustomView.setVisibility(View.VISIBLE);
            mContentLayout.setVisibility(View.GONE);
            mCustomViewCallBack = callback;
            fl_video.addView(mCustomView);
            fl_video.setVisibility(View.VISIBLE);
            fl_video.bringToFront();
            //全屏
            //設定橫屏
            rootLayout.setBackground(ContextCompat.getDrawable(mContext,R.color.total_black));
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }

        @Override  //退出全屏
        public void onHideCustomView() {
            super.onHideCustomView();
            Log.d("MyInfo","onHideCustomView...");
            if (mCustomView == null) {
                return;
            }
            mCustomView.setVisibility(View.GONE);
            mContentLayout.setVisibility(View.VISIBLE);
            fl_video.removeView(mCustomView);
            mCustomView = null;
            fl_video.setVisibility(View.GONE);
            mCustomViewCallBack.onCustomViewHidden();
            rootLayout.setBackground(ContextCompat.getDrawable(mContext,R.color.white));
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }

相關文章