Android WebView无法播放视频或直播,关闭界面后任在播放的问题;

1、设置webview属性:

webView.setWebChromeClient(new MyWebChromeClient());

        webSettings = webView.getSettings();

        webSettings.setJavaScriptEnabled(true);

        webSettings.setPluginState(WebSettings.PluginState.ON);

        webSettings.setUseWideViewPort(true); 

        webSettings.setAllowFileAccess(true); 

        webSettings.setSupportZoom(true); 

        webSettings.setLoadWithOverviewMode(true);

        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

            webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);

        }

        webSettings.setUseWideViewPort(true);

        webView.addJavascriptInterface(new JavaScriptObject(this), "android");

2、设置AndroidManifest.xml:

//开启硬件加速

<activity android:name=".webview.WebViewAdActivity"  android:hardwareAccelerated="true"/>

3、关闭界面任在播放的问题:

@Override
public void onPause() {
super.onPause();
webView.onPause();
webView.pauseTimers();
} @Override
public void onResume() {
super.onResume();
webView.resumeTimers();
webView.onResume();
} @Override
protected void onDestroy() {
webView.destroy();
webView = null;
super.onDestroy();
}
上一篇:go微服务框架go-micro深度学习 rpc方法调用过程详解


下一篇:Android 使用MediaPlayer 播放 视频