Wordpress: how to get events from the default player?

I am currently using Wordpress 4.0 and all my audio on posts / pages are embedded using the default Wordpress player - via shortcode like:

[audio http://en.support.files.wordpress.com/2012/05/mattmullenweg-interview.m4a]

Now I want to track how many times the play button is pressed. So my question is, how can I capture this player's events?

PS: I've tried the following (and it didn't work):

$('.mejs-playpause-button button').click(function(){
    console.log('TESTING');
});

      

enter image description here

+3


source to share


1 answer


It is possible that event support for this button is being prevented by the MediaElementJS library that controls the audio element.

Alternatively, I would suggest listening for the "play" events on the MediaElementJS, or selecting your own HTML audio element directly and listening for the "play" event on that object.

I briefly tried to get a MediaElementJS instance for the player, but it's hard to hold due to the way Wordpress is making these instances .



However, you can add an event listener to an audio element and record the number of times that element is fired:

  $('audio').on('play', function(){                           
        console.log("play");                                                  
   }); 

      

This may not be the best solution if there are multiple elements on the page.

0


source







All Articles