Ravi
Ravi

Reputation: 35569

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

Upvotes: 8

Views: 2303

Answers (4)

Ashish Bahl
Ashish Bahl

Reputation: 33

I had similar issues with WebViews malfunctioning across my app. I decided to use the complementary function of onPause() (i.e. onResume()) in the same way:

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

Upvotes: 0

Mohammad Roshani
Mohammad Roshani

Reputation: 769

You write you have A WebView and 3 tab, do you use from that WebView in All tab?

My Solution is that you use from Another WebView in other tab and if it tabs be selected some data that maybe be needed,be send to them.

In fact this don't solve your question, but i hope that can solve your problem.

Upvotes: 0

Baqar Gogia
Baqar Gogia

Reputation: 367

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?

Upvotes: 1

KoalaKoalified
KoalaKoalified

Reputation: 697

On older devices (api <=21) I don't think this is actually possible, but an easy way to retrieve the given idea of a webview's inner controls are to:

Navigate to ../Android/android-sdk/tools/androiduiautomator.bat and open it up.

Make sure your device is connected via an ADB bridge (which it most likely will be)

Take a device screenshot of your screen and hover over the webkit control you want to call onPause which should bring up some information to the right hand side of your screen.

Substitute the id for

Class.ForName("yourId") 

and just call a generic click event which should cause an inner effect of pausing. It could also be

Field.getDeclaredField("Id")

but I'm not positive. One of those two should procure a desired result.

Upvotes: 0

Related Questions