Answering your question (although I see that you found a different solution), I think I found your error:
The second time you enter Ebuc.manageAudio (), Ebuc.bgsong is already configured, and you just create a new Audio Ebuc.bgsong = new Audio(...) without adding a listener to it, so you will not be notified of any "timeupdate" events when playing the second audio file.
You must also remove the listener from the previous playback sound.
So, if everything else is fine, I think this should fix it:
Ebuc.manageAudio = function(){ var listener = function (event) { if (this.currentTime > (this.duration - 1) && Ebuc.bgnext) { Ebuc.manageAudio(); console.log("aduio"); Ebuc.bgnext = false; } if(this.currentTime < 2){ Ebuc.bgnext = true; console.log("reset"); } console.log(event); console.log("listener active") }; var color = Level.current.color; if(Ebuc.bgsong != null) { Ebuc.bgsong.removeEventListener('timeupdate', listener, true); } Ebuc.bgsong = new Audio('assets/sound/' + Resources.audioSetList[color].getcurrentsong()); Ebuc.bgsong.addEventListener('timeupdate', listener, true); Ebuc.bgsong.play(); Resources.audioSetList[color].next(); };
Moreover, I think that if you correctly remove the listener from the previous playback sound, you will not need this bgnext hack at all:
var listener = function (event) { if (this.currentTime > (this.duration - 1)) { Ebuc.manageAudio(); console.log("aduio"); } console.log(event); console.log("listener active") }; Ebuc.manageAudio = function () { var color = Level.current.color; if (Ebuc.bgsong != null) { Ebuc.bgsong.removeEventListener('timeupdate', listener, true); } Ebuc.bgsong = new Audio('assets/sound/' + Resources.audioSetList[color].getcurrentsong()); Ebuc.bgsong.addEventListener('timeupdate', listener, true); Ebuc.bgsong.play(); Resources.audioSetList[color].next(); };
Let me know if this worked :)
Yoav aharoni
source share