Mads K
Mads K

Reputation: 837

Mediaelement.js wont play with Flash-fallback

I'm using Mediaelement.js to play some video and using javascript to get autoplay working. It works perfectly in Chrome, and IE10, but when it comes to Firefox and IE8 I have a problem with the flash fallback. The following works in Chrome:

jQuery('video,audio').mediaelementplayer();

if(autoPlay == "true") {
  player = new MediaElementPlayer("#"+currentPage+" video,audio");
  player.play();
}

IE8 returns the following: enter image description here

And firefox returns no errors, but if I add an alert(alert("hallo");) in front of player.play(), it plays when I dismiss the alert-box.

I can't add fiddle, because of heavy use of XML.

Upvotes: 1

Views: 667

Answers (3)

Mads K
Mads K

Reputation: 837

Yeah sorry, solved it a half year later:

As mentioned, the play event must be invoked in the success function

jQuery("video,audio").mediaelementplayer();

if(autoPlay == "1") {
  media = jQuery("#"+currentPage+" video,audio")[0];
  new MediaElement(media, {success: function(media) {
      media.play();
  }});
}

Upvotes: 0

JFK
JFK

Reputation: 41143

Some browsers (webkit specifically) may trigger the play() method before the video is completely ready and the video may just hang while loading.

I would advice to add an event listener to detect when the video can actually play before triggering the play() method like :

success : function (media, domObject) {
    media.addEventListener('canplay', function () {
        media.play();
    }, false);
} // success

Upvotes: 0

john-jones
john-jones

Reputation: 7780

The player isn't loaded up and ready to play when the script presses the play button.

The script needs to press the play button inside the success function in the mediaelement instance creation.

See here:
How do I get mediaelement.js player state (paused, volume, etc.)?

Upvotes: 1

Related Questions