Hey guys i build a AudioQueue for my game and somehow it doenst work, code:
handleAction: function ( src )
{
var oAudio = document.getElementById('voice');
if(this.lastSoundPlayed == undefined || src != this.lastSoundPlayed.src) // checks if there is an actual new sound incoming.
{
var self = this;
oAudio.src = src; //sets the source
oAudio.load();
oAudio.onloadeddata = oAudio.play(); // when loaded play the sound
oAudio.onended = self.soundDone( self, oAudio ); //when the sound is finished fire the soundDone function
}
}
the soundDone() function:
soundDone: function( self , oAudio )
{
console.log("Finished"); //logs that the sound is finished
self.lastSoundPlayed = oAudio; //sets the lastSoundPlayed
self.sendNotification(self.SC_ACTION_COMPLETE); //fires off a notification that the sound is finished (im using pureMVC)
}
well the actual problem is that he thinks that the sounds is instant finished. ive logged the duration of my sounds and there all NaN? i’ve checked that with console.log(oAudio.duration). i dont know why this is happening. i also have background music wich i play the same way as these sounds and with the background music is nothing wrong.
Someone can help me?
EDIT: this is the audio tag for my audio:
<audio id="voice" src="mySound.mp3" controls preload="auto" ></audio>
found it couple of weeks ago, the sounds wasnt fully loaded when i called it.