I'm looking for the best way in which to log that an embedded audio file within a page is played. My first instinct is to try and fire off an AJAX request whenever the Play button is pressed.

I'm looking at the [Media Events docs](https://developer.mozilla.org/en/docs/Web/Guide/Events/Media_events), and believe that the [`playing`](https://developer.mozilla.org/en-US/docs/Web/Events/playing) event is the one I'm after. Is this correct? I'm also worried it might fire off AJAX requests every time the play button is pressed and not just the first time (if they pause and unpause, for instance) and this might give skewed logs.

This is the listener example the documents give for media events:

```
var v = document.getElementsByTagName("video")[0];
v.addEventListener("seeked", function() { v.play(); }, true);
v.currentTime = 10.0;

```

But how could I integrate this in to the following code:

```
<audio id="123" controls>
    <source src="../uploads/filename.mp3" type="audio/mpeg">
</audio>

```

I have attempted the following, but nothing seems to be happening:

```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('audio').each(function() {
            var id = $(this).attr('id');
            $(this).addEventListener("playing", function() {
                alert(id);
            });
        });
    });
</script>

```