javascriptdom-eventsmediaelement.js

mediaelement 'playing' event tracking


I have the following simple code that initiates the mediaelement audio plugin:

$('audio,video').mediaelementplayer({
    audioWidth: 300,
    audioHeight: 30
});

I need to track the playing event; I've tried the following code without any luck:

var player = document.getElementsById('player2');
player.playing = function(e) {
   alert('OMG! You played a song!');
}

Solution

  • Ok so I've figured it out...

    $('audio,video').mediaelementplayer({
        audioWidth: 300,
        audioHeight: 30,
    
        success: function(mediaElement, domObject) {
            mediaElement.addEventListener('loadeddata', function() {
                console.log('addEventListener - loadeddata')            
            }, false);
        },
        error: function() {
            //alert('Error setting media!');
        }
    
    });