Yaniv Efraim
Yaniv Efraim

Reputation: 6713

Autostart html5 video on a Webview not working on Android 4.2.2

I am using an Android html5Webview with html5 element.

I am auto-playing the video from javascript (when the page loads) using this code:

document.getElementsByTagName('video')[0].play();

(taken from here:).

This works perfectly on Android 4.1.2 (Samsung Galaxy 3, note2). On Android 4.2.2 (Galaxy S4, Nexus 10), the video does not auto-play. It does start playing when clicking the screen.

I tried adding timeout to the play event, it did not work. Any ideas what could be the cause of it?

tnx! Yaniv

Upvotes: 1

Views: 3414

Answers (2)

Midhun Krishna
Midhun Krishna

Reputation: 1759

For Jelly Bean and above, this can easily get the job done:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
    webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
}

Upvotes: 1

Yaniv Efraim
Yaniv Efraim

Reputation: 6713

It seems that the answer was here.

The autostart did not work on regular javascript page load event, but did work when triggered from within Android's "onPageFinished" event.

Upvotes: 3

Related Questions