locked
audio play event firing only once

    Question

  • I'm writing a xylophone app. The idea is that a sequence of notes will play and the key that corresponds to the note being played will change color

    Each note is a HTML5 audio tag, and I added the functions that change the color of the keys to the play and ended events.  My code looks like this

    document.getElementById("cancion_do_60").addEventListener("play", function (event) { prender_tecla(1) }, false);
    
    document.getElementById("cancion_do_60").addEventListener("ended", function (event) { apagar_tecla(1) }, false);

    When I play the music, the key only lights up the first time the note is played.  I added console log statements to the functions called by the event handlers, and I found out that the play event only fired the first time the note was played, but the ended event fired every time the note ended as expected.

    Any help with this will be greatly appreciated

    TIA

    Saturday, February 22, 2014 3:45 AM

Answers

  • I found out how to solve it, even though I'm not sure why it works.

    If I pause the video when it ends, then the play event fires when it should. 

    Saturday, February 22, 2014 11:46 PM