Autoplay MediaElementPlayer

Gencebay D. picture Gencebay D. · Mar 22, 2011 · Viewed 40.5k times · Source

I want that when web site page loaded play video automatically.

I referenced to jquery.js, mediaelementplayer.js and mediaelementplayar.min.css on my page and added video tag.

I tried so many ways, e.g. autoplay = true and use javascript code but I couldn't get it to work.

I'm using BlogEngine.Net 2.0.

How can I do that?

Answer

xoreax picture xoreax · Jun 26, 2012

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

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() {
                // Player is ready
                mediaElement.play();
            }, false);
        }
    },
    error: function() {
        alert('Error setting media!');
    }
});