在我的项目中使用 webview 加载使用 iframe 概念的视频 url,但调用下一个意图无法停止播放声音或暂停视频。或用于在 webview 中加载视频的任何其他编码
我的代码:
public class Webviewfullscreen extends Activity {
WebView webview;
LinearLayout webViewPlaceholder;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.webviewfull);
webViewPlaceholder=(LinearLayout) findViewById(R.id.webViewholder);
String VideoUrl=this.getIntent().getExtras().getString("url");
webview = (WebView) findViewById(R.id.webView1);
webViewDisplay(VideoUrl, webview);
}
private void webViewDisplay(final String weburl, final WebView www) {
new Handler().post(new Runnable() {
@SuppressWarnings("deprecation")
@Override
public void run() {
WebSettings settings = www.getSettings();
String Url = "<html> <head> <style type=text/css> iframe {height:100%;width:100%;margin:0;padding:0;overflow:scroll;} body {background-color:#000; margin:0;}</style> </head> <body> <iframe width=240px height=220px src="
+ weburl
+ " frameborder=0 webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></body></html>";
settings.setLightTouchEnabled(true);
www.getSettings().setJavaScriptEnabled(true);
if (Build.VERSION.SDK_INT < 8) {
www.getSettings().setPluginsEnabled(true);
} else {
www.getSettings().setPluginState(PluginState.ON);
}
www.setWebChromeClient(new WebChromeClient());
www.loadDataWithBaseURL(null, Url, "text/html", "utf-8", null);
}
});
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
// do something on back.
System.out.println("on finish");
webViewPlaceholder.removeView(webview);
webview.loadUrl("");
webview.removeAllViews();
webview.destroy();
webview = null;
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
请帮助如何停止视频