Android:webView加载h5网页视频,播放不了,以及横屏全屏的问题和实现自定义加载进度条的效果

1、webView加载h5网页视频,播放不了,android3.0之后要在menifest添加硬件加速的属性 android:hardwareAccelerated="true"。

2、接着是视屏播放实现横屏全屏效果,以及自定义加载提示和播放进度条。

public class myWebChromeClient extends WebChromeClient {

        @Override
        public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
            LogUtils.i(NewsDetailsActivity.class, "title:" + title);
            if (getIntent().getStringExtra("ifIsFromFocus") != null) {
                if (ifFirstWebPage == 0) {
                    ifFirstWebPage++;
                    pre_title = title;
                }
                shareTitle = title;
                tvTitle.setText(title);
            }
        }

        private View xprogressvideo;

        // 播放网络视频时全屏会被调用的方法
        @Override
        public void onShowCustomView(View view, CustomViewCallback callback) {
            rlTopTitle = (RelativeLayout) findViewById(R.id.rlTopTitle);
            rlTopTitle.setVisibility(View.GONE);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            mWebView.setVisibility(View.INVISIBLE);
            // 如果一个视图已经存在,那么立刻终止并新建一个
            if (xCustomView != null) {
                callback.onCustomViewHidden();
                return;
            }
            video_fullView.addView(view);
            xCustomView = view;
            xCustomViewCallback = callback;
            video_fullView.setVisibility(View.VISIBLE);
        }

        // 视频播放退出全屏会被调用的
        @Override
        public void onHideCustomView() {
            if (xCustomView == null)// 不是全屏播放状态
                return;
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            xCustomView.setVisibility(View.GONE);
            video_fullView.removeView(xCustomView);
            xCustomView = null;
            video_fullView.setVisibility(View.GONE);
            xCustomViewCallback.onCustomViewHidden();
            mWebView.setVisibility(View.VISIBLE);
            rlTopTitle = (RelativeLayout) findViewById(R.id.rlTopTitle);
            rlTopTitle.setVisibility(View.VISIBLE);
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
            mWebView.getSettings().setBuiltInZoomControls(true);
        }

        // 视频加载时进程loading
        @Override
        public View getVideoLoadingProgressView() {
            if (xprogressvideo == null) {
                LayoutInflater inflater = LayoutInflater
                        .from(NewsDetailsActivity.this);
                xprogressvideo = inflater.inflate(
                        R.layout.video_loading_progress, null);
            }
            return xprogressvideo;
        }

    }

 

xwebchromeclient = new myWebChromeClient();
            mWebView.setWebChromeClient(xwebchromeclient);

进度加载提示和播放进度条的布局文件如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/progress_indicator"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerInParent="true"
 android:orientation="vertical" >
 <ProgressBar
 android:id="@android:id/progress"
 style="?android:attr/progressBarStyleLarge"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_gravity="center" />
 <TextView
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_gravity="center"
 android:paddingTop="5dip"
 android:text="正在玩命加载视频中。。。"
android:textColor="?android:attr/textColorPrimary"
 android:textSize="14sp" />
</LinearLayout>

 

你可能感兴趣的:(Android:webView加载h5网页视频,播放不了,以及横屏全屏的问题和实现自定义加载进度条的效果)