portfoliobuilder
portfoliobuilder

Reputation: 7866

How to stop audio playing on websites loaded in webView?

How can I stop the audio of a video that is playing on a website in a webview after I have left the Activity? In other words, lets say I have both Activity A and Activity B. I load up a website in Activity B that is playing a video, and then press the back button to go to Activity A. My experience is that the sound continues to play while on Activity A. How can I stop this audio?

I am not doing anything special with displaying the webpage, I use a webView

<WebView
        android:id="@+id/fl_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

And I declare the following settings

flContainer = (WebView) findViewById(R.id.fl_container);

        flContainer.getSettings().setJavaScriptEnabled(true);
        flContainer.getSettings().setLoadWithOverviewMode(true);
        flContainer.getSettings().setUseWideViewPort(true);
        flContainer.setWebChromeClient(new WebChromeClient());  

I then display a website that has a video in it and play the video. After pressing the back button the audio continues to play. How can I stop this as there is no mediaPlayer to destroy or anything like this? Thanks in advance!

Upvotes: 1

Views: 2126

Answers (1)

Tyler Lazenby
Tyler Lazenby

Reputation: 451

Either destroy the previous webview as this one will continue running in the background by default, or change the player element to something else.

Upvotes: 2

Related Questions