How do I stop Flash after leaving a WebView?

后端 未结 6 1802
忘掉有多难
忘掉有多难 2020-12-30 08:11

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 lo

相关标签:
6条回答
  • 2020-12-30 08:31

    Calling webvew.destroy() in onDestroy() worked for me.

    0 讨论(0)
  • 2020-12-30 08:35

    The webViwe destory approach did not work for me - it worked well on the first close of the webview, but subsequent calls to the webview caused a crash.

    I ended up doing this:

    _webView.loadData("", "text/html", "utf-8");

    from my activity finish() method.

    0 讨论(0)
  • 2020-12-30 08:37

    If you are as lucky as I am, even this won't be enough to end a youtube streaming! The sound is still playing no matter what!

    @Override
    protected void onDestroy() {
        super.onDestroy();
    
        // Stopping a webview and all of the background processes (flash,
        // javascript, etc) is a very big mess.
        // The following steps are to counter most of the issues seen on
        // internals still going on after the webview is destroyed.
    
        mWebView.stopLoading();
        mWebView.loadData("", "text/html", "utf-8");
        mWebView.reload();
    
        mWebView.setWebChromeClient(null);
        mWebView.setWebViewClient(null);
    
        RelativeLayout layout = (RelativeLayout) findViewById(R.id.webviewRelativeLayout);
        layout.removeView(mWebView);
        mWebView.removeAllViews();
        mWebView.clearHistory();
        mWebView.destroy();
        mWebView = null;
    }
    
    0 讨论(0)
  • 2020-12-30 08:49

    I combined some of the answers here, and this worked for me:

    @Override
    protected void onDestroy()
    {
        super.onDestroy();
    
        webView.stopLoading();
        webView.loadData("", "text/html", "utf-8");
        webView.destroy();
    }
    
    0 讨论(0)
  • 2020-12-30 08:51

    This approach works me. I call it on back button press.

    webview.stopLoading(); 
    webview.loadUrl("");
    webview.reload();
    webview = null;
    
    0 讨论(0)
  • 2020-12-30 08:52

    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");
    }
    

    I posted this same solution here: android WebView stop Flash plugin onPause

    0 讨论(0)
提交回复
热议问题