NullPointerException
NullPointerException

Reputation: 37579

webView.onPause() does not stop audio of a internal video playing

I have a webview that it is showing a video. I want that when the activity onpauses the video stop playing audio and when the activity resumes the video must resume playing audio.

tryed with webView.onPause() but does not work. audio is still playing even with the device locked or with the app closed.... (lol)

exists a real way to pause audio playback of a video inside a webview?

thanks

Upvotes: 2

Views: 2069

Answers (2)

Dastin
Dastin

Reputation: 4497

To me, I have to interject to HTML code to pause the video element in HTML file.

Link util to interject java to HTML: https://github.com/mttdat/utils/blob/master/utils/src/main/java/mttdat/utils/WebViewUtils.java

How to use in the activity (Java):

enter image description here

How the HTML looks like:

enter image description here

Upvotes: 1

Jorgesys
Jorgesys

Reputation: 126445

You can do it by using the method onPause() of the of WebView when is executed the method onPause() of your Activity

@override
public void onPause() {
        super.onPause();
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
        webview.onPause();
        }
}

it works for API >= 11 (Honeycomb)

Upvotes: -1

Related Questions