Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autoplay MediaElementPlayer

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?

like image 830
Gencebay Avatar asked Mar 22 '11 16:03

Gencebay


1 Answers

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!');
    }
});
like image 60
xoreax Avatar answered Sep 30 '22 20:09

xoreax