How to add events to flash fallback for medialemet

2019-09-03 19:34发布

问题:

I am using mediaelement.js, the player is working as intended with chrome but for firefox the events are not firing. Are there any specific events that don't work on firefox? Which events are available?

I have tried both the loadeddata and progress events, but neither are getting called in firefox.

player.addEventListener('loadeddata', function() {
  jQuery('.mejs-overlay-button').trigger('click');
}, false);

回答1:

Are you adding the events inside the success function of your mediaelementplayer() function?

(function($) {
    $(document).ready(function() {
        $('video').mediaelementplayer({
            success: function (mediaElement, domObject) {
                //add events here
                mediaElement.addEventListener('loadeddata', function() {
                    console.log('loadeddata');
                });

                //timeupdate event
                mediaElement.addEventListener('timeupdate', function(e) {
                    console.log(mediaElement.currentTime);
                });
            }
        });
    });
})(jQuery);