jquerymediaelement.js

How to detect pause button click in mediaelement?


I am trying to detect click event on mediaelement pause button

http://jsfiddle.net/wLu2v/9/

var player = new MediaElementPlayer('.player_1');

$('body').on('click', '.mejs-pause', function (e) {
    $('.items').append('<li>paused</li>');
});

I also tried with mejs-pause button and few other combos but cant detect the event . Any help is appreciated


Solution

  • You need to add an event listener to MEJS initialization script on success setting like :

    var player = new MediaElementPlayer('.player_1', {
        success: function (mediaElement, domObject) {
            mediaElement.addEventListener('pause', function () {
                // do something here
                $('.items').append('<li>paused</li>');
            }, false);
        }
    });
    

    See your forked JSFIDDLE