Pause WebView video instead of whole WebView - android

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

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?

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.

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.

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

Related

WebRTC Android Share Screen the second time give black screen

I'm having trouble solving this bug and hope someone can guide me. I created the share screen function in android with WebRTC (EglBase). it works perfectly fine until the user stops sharing and then shares again, the participant's screen will be a black screen, and can't see the content.
I have already check the SurfaceViewRenderer is assigned correctly. I believe the problem may be on how I implemented the init() and release() functions.
In this function, I init the screen share video
EglBase root = EglBase.create();
screenShare.init(root.getEglBaseContext(), null);
screenShare.setZOrderMediaOverlay(true);
remoteParticipant.setView(screenShareVideoView);
In this function, I release the screen share
screenShare.clearImage();
screenShare.release();
screenShare.setVisibility(View.INVISIBLE);
Maybe I re-init the view after release() incorrectly.

Disabling the youtube icon on the YouTubeStandalonePlayer in android?

I just wanted to know how to disable the youtube icon that comes in the YouTubeStandalonePlayer. Is it possible?
I don't want to take the user to youtube on clicking the icon. Is there any way to disable the youtube icon?
The below is the code how I am playing the the video using the YouTubeStandalonePlayer.
String videoId = getVideoId(cardsInfo.getCard_video_url());
Intent intent = YouTubeStandalonePlayer.createVideoIntent(getActivity(), getResources().getString(R.string.android_key), videoId, 0, true, false);
startActivity(intent);
According to the API, you can't.
But, you can try and use the other (not standalone) classes, which might give you better control as suggested in the docs: There are two ways to play videos. The first option is to place a YouTubePlayerFragment or YouTubePlayerView in your View hierarchy and then use the YouTubePlayer to control video playback in the View. **This gives a fine control of the experience**. If they don't let it, you could atleast have better control of the flow/UI-visibility because you are controling the Activity (in contrast of giving the control to the standalone activity)

Detect address bar changes firefox android extension

I'm working on a firefox for android addon, and there is a function that i need to be fired every time a new page (tab) is loaded: a new tab is opened or the address of the current tab changes. I tried to use listener ("load"/"tabSelect") but the first one didn't work and the second doesn't detect the address bar changes:
window.BrowserApp.deck.addEventListener("load", onPageLoad, true);
Should I add more than one listener? and I found this, but it doesn't work for firefox for android. Thank you for your help.
I don't know why "load" is not working for you. I do know that "load" is sometimes not called, when loading a page from back/forward session history for example. To work around that, you could try using the "pageshow" event. That will be called for any page-change.
For more info see: https://developer.mozilla.org/en-US/docs/Code_snippets/Mobile

WebView throws Receiver not registered: android.widget.ZoomButtonsController

I see this exception sporadically raising up in my application (in the wild).
The WebView is used to display a jpg (using the zoom/scroll-capabilities of the Android version/the device instead reinventing the wheel and do all the reflection stuff).
I have no idea why this exception eventually could come up. Basically I can only think of an Android bug.
What I do (everything in GUI thread):
display a thumbnail as preview first
set getSettings().setBuiltInZoomControls(false)
when the regular picture is loaded, display that one instead
set getSettings().setBuiltInZoomControls(true)
Why setting ZoomControls on/off: The thumb should not be zoomable, as the WebView resets this on loadData as soon as the regular picture is available and displayed. Would be some bad user experience.
Example device this is happening:
HTC Desire#htc_wwe/htc_bravo/bravo/bravo:2.2/FRF91/226611:user/release-keys
I have exactly the same device/software and it never happend to me...
Any ideas?
Regards,
Oliver
I don't like to answer myself, but littleFluffyKitty did not (only in comment).
Solution is in How to safely turn WebView zooming on and off as needed
a) create your own WebView class
public class MyWebView extends WebView {
b) add in it's onDestroy() method:
getSettings().setBuiltInZoomControls(true);
That's it. Thanks to that, no more of those Exceptions show up.

What DOM events are available to WebKit on Android?

I'm building a mobile web app targeting Android users. I need to know what DOM events are available to me. I have been able to make the following work, but not terribly reliably:
click
mouseover
mousedown
mouseup
change
I have not been able to get the following to work:
keypress
keydown
keyup
Does anyone know the full list of what is supported and in what contexts (e.g., is onchange only available to form inputs?)? I can't find a reference for this on The Googles.
Thanks!
Update: I asked the same question on the Android developers list. I will be doing some more testing and will post my results both here and there.
OK, this is interesting. My use case is that I have a series of links (A tags) on a screen in a WebKit view. To test what events area available, using jQuery 1.3.1, I attached every event listed on this page (even ones that don't make sense) to the links then used the up, down, and enter controls on the Android emulator and noted which events fired in which circumstances.
Here is the code I used to attach the events, with results to follow. Note, I'm using "live" event binding because for my application, the A tags are inserted dynamically.
$.each([
'blur',
'change',
'click',
'contextmenu',
'copy',
'cut',
'dblclick',
'error',
'focus',
'keydown',
'keypress',
'keyup',
'mousedown',
'mousemove',
'mouseout',
'mouseover',
'mouseup',
'mousewheel',
'paste',
'reset',
'resize',
'scroll',
'select',
'submit',
// W3C events
'DOMActivate',
'DOMAttrModified',
'DOMCharacterDataModified',
'DOMFocusIn',
'DOMFocusOut',
'DOMMouseScroll',
'DOMNodeInserted',
'DOMNodeRemoved',
'DOMSubtreeModified',
'textInput',
// Microsoft events
'activate',
'beforecopy',
'beforecut',
'beforepaste',
'deactivate',
'focusin',
'focusout',
'hashchange',
'mouseenter',
'mouseleave'
], function () {
$('a').live(this, function (evt) {
alert(evt.type);
});
});
Here's how it shook out:
On first page load with nothing highlighted (no ugly orange selection box around any item), using down button to select the first item, the following events fired (in order): mouseover, mouseenter, mousemove, DOMFocusIn
With an item selected, moving to the next item using the down button, the following events fired (in order): mouseout, mouseover, mousemove, DOMFocusOut, DOMFocusIn
With an item selected, clicking the "enter" button, the following events fired (in order): mousemove, mousedown, DOMFocusOut, mouseup, click, DOMActivate
This strikes me as a bunch of random garbage. And, who's that cheeky IE-only event (mouseenter) making a cameo, then taking the rest of the day off? Oh well, at least now I know what events to watch for.
It would be great if others want to take my test code and do a more thorough run through, perhaps using form elements, images, etc.
Since this is the second most popular Android + JavaScript post on SO (which is just a sad commentary on the state of web development targeting the Android platform), I thought it may be worthwhile including a link to pkk's touch event test results at http://www.quirksmode.org/mobile/tableTouch.html and also http://www.quirksmode.org/mobile/ in general.
As of Android 1.5, the same touch(start|move|end|cancel) events that the iPhone supports work in Android as well.
One problem I found was that touchmove ends get queued up. No workaround yet.

Categories

Resources