Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pause WebView video instead of whole WebView

I have a WebView with youtube video and 3 tabs. YouTube video is available in 1st Tab while in other 2 tabs there is a content.

Now i want to pause a video when user moves to other tabs. I have tried with

webView.onPause();

and

Class.forName("android.webkit.WebView")
                                .getMethod("onPause", (Class[]) null)
                                .invoke(webView, (Object[]) null);

but it is pausing whole WebView and my other 2 tabs are also not responding. How to stop just a video instead of whole WebView process

like image 550
Ravi Avatar asked Jan 27 '17 11:01

Ravi


1 Answers

You can evaluate Javascript from android and stop video playing.

webView.evaluateJavascript(javascript, callBack); or older versions. webView.loadUrl(javascript); check this https://developer.android.com/reference/android/webkit/WebView.html#evaluateJavascript(java.lang.String,android.webkit.ValueCallback

What type video do you have? iframe or video tag?

like image 145
Baqar Gogia Avatar answered Nov 22 '22 13:11

Baqar Gogia