webview播放视频
WebView webView = (WebView) findViewById(R.id.webView);webView.setDownloadListener(new DownloadListener() {@Overridepublic void onDownloadStart(String url, String userAgent,String contentDisposition, String mimetype, long contentLength) {Intent intent = new Intent(Intent.ACTION_VIEW);intent.setDataAndType(Uri.parse(url), mimetype);try {startActivity(intent);}catch (ActivityNotFoundException e){Log.w("YourLogTag", "Couldn't find activity to view mimetype: " + mimetype);e.printStackTrace();} catch (Exception e) {e.printStackTrace();}}});webView.setWebViewClient(new WebViewClient(){public boolean shouldOverrideUrlLoading(Webview view, String url){ if(url.endsWith(".mp4") || url.endsWith("some other supported type")){ Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); //warning no error handling will cause force close if no media player on phone. return true; } else {view.loadUrl(url);}return true;}});
public void onPause() {//继承自Activitysuper.onPause();webView.onPause();}public void onResume() {//继承自Activitysuper.onResume();webView.onResume();}
webView.pauseTimers();webView.stopLoading();webView.loadData("<a></a>", "text/html", "utf-8");