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;}});WebView退出后flash视频播放器无法退出的问题 .
转自:http://blog.csdn.net/a345017062/article/details/6788502
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");这样直接就把视频停掉无法恢复了。