We are serious
about web platforms

Centurion mag, this is where you'll find release announcements, developer tips, and periodic updates from the Centurion team.

How to "autoplay" HTML5 video on Android

Written by Mathias Desloges in Labs on 19/05/11

Have you ever try to play with the new HTML5 video tag on an Android device? we have and here is an stange issue which we faced.

Let's set up the context, we want our video starts playing just after the page load complete.

According to the HTML5 specification, we should use the "autoplay" attribute, but it has no effect in Android. So we tried with a little script tha call the play function after the page has loaded.

function callback () {
    document.querySelector('video').play();
}

window.addEventListener("load", callback, false);

This reproduce well the behavior of the "autoplay" attribute on a classic desktop browser, but on an Android browser it fails.

we tried to attach the previously defined "callback()" function to a click event on a abitrary node, and the video starts playing well "on click" (normal behavior).

And while continu working on the page html code, we found the solution !

<video poster preload="true">
    <source src="video.mp4"  type="video/mp4">
</video>

don't ask me why, but after adding the "poster" attribute it works !

Tags: Javascript , html5 , video

1 comment

By Vasili

Not working :(
Asus eee pad, android 3.2. Only manual play.

Add a comment

Please, fill in the field with the charactere 1 of this string zywexofe
 
 
Fork me on Github