离开 WebView 后如何停止 Flash? [英] How do I stop Flash after leaving a WebView?
问题描述
我有一个应用程序,当用户单击按钮时,我将其放在一起以在 web 视图中流式传输 Flash 视频.
I have an app that I've put together to stream flash video in a webview when a user clicks a button.
它做得很好,但在退出或失去焦点后,它看起来会继续使用数据一段时间,直到我假设系统关闭活动.如果我手动退出活动屏幕,数据使用几乎立即停止.只需退出,它就可以继续运行一段时间.
It does this fine, but after backing out or losing focus, it looks like it continues to use data for a while until I assume when the system shuts the activity down. If I manually kill out of the activity screen, data use stops almost immediately. Just backing out and it can keep going for a while.
谁能帮我解决我的代码,我真的很感激!
Can someone help me out with my code, I would really appreciate it!
import java.lang.reflect.Method;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class Video extends Activity {
private WebView webview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video);
webview = (WebView) findViewById(R.id.webview);
// resumeTimers() to account for the webview refcount bug (hopefully)
webview.resumeTimers();
WebSettings webSettings = webview.getSettings();
webview.getSettings().setJavaScriptEnabled(true);
webSettings.setPluginsEnabled(true);
webview.setVerticalScrollBarEnabled (false);
webview.setHorizontalScrollBarEnabled (false);
webview.loadUrl("http://www.nasa.gov/multimedia/nasatv/nasatv_android_flash.html");
}
@Override
protected void onPause() {
pauseBrowser();
super.onPause();
}
@Override
protected void onResume() {
resumeBrowser();
super.onResume();
}
private void pauseBrowser() {
// pause flash and javascript etc
callHiddenWebViewMethod(webview, "onPause");
webview.pauseTimers();
}
private void resumeBrowser() {
// resume flash and javascript etc
callHiddenWebViewMethod(webview, "onResume");
webview.resumeTimers();
}
private void callHiddenWebViewMethod(final WebView wv, final String name){
if( webview != null ){
try {
Method method = WebView.class.getMethod(name);
method.invoke(webview);
} catch (final Exception e) {
}
}
}
}
推荐答案
我对这个问题有点困惑,但我认为您是说 Flash 视频即使在 Activity 关闭后仍继续播放.我遇到了类似的问题.以下对我有用:
I'm a bit confused by the question, but I think you're saying that flash video keeps on playing even after the activity is closed. I ran into a similar issue. The following worked for me:
@Override
protected void onDestroy() {
super.onDestroy();
final WebView webview = (WebView)findViewById(R.id.webPlayer);
// Calling .clearView does not stop the flash player must load new data
webview.loadData("", "text/html", "utf-8");
}
我在这里发布了同样的解决方案:android WebView stop Flash plugin onPause
I posted this same solution here: android WebView stop Flash plugin onPause
这篇关于离开 WebView 后如何停止 Flash?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!