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.

$('#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!');
    }
});

One comment

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

Leave a Reply

Your email address will not be published. Required fields are marked *

*