Autoplay for media element js

This is a bug in MediaElementJS, autoplay works for native and silverlight, but needs a little help with Flash.mediaelementjs_400x400

You can listen for canPlay event and start playing as soon as the flash player is ready.

setTimeout tricks may fail in race conditions.

[code lang=”javascript”]
$(‘#playerid’).mediaelementplayer({
plugins: [‘flash’, ‘silverlight’],
success: function(mediaElement, domObject) {
if (mediaElement.pluginType == ‘flash’) {
mediaElement.addEventListener(‘canplay’, function() {
mediaElement.play();
}, false);
}
},
error: function() {
alert(‘Error setting media!’);
}
});[/code]


Posted

in

, ,

by

Tags:

Comments

One response to “Autoplay for media element js”

  1. Nicolas Avatar
    Nicolas

    Simple but really useful. You save me a lot of time. Thanks