Greetings! I have successfully developed an app using Phaser and now I am eager to create a sequence comprising of two distinct sounds:
- "You have" (saved as audioSound[0])
- "Finished" (also saved as audioSound[1])
My goal is to be able to repeatedly use the first sound while incorporating various words or sentences for the second one. I am struggling with getting these sounds to play in succession rather than simultaneously.
Currently, my code looks like this:
audioSound[0].play();
audioSound[1].play();
othercode...
This setup plays both sounds at the same time. Any suggestions on how to ensure that the sounds play one after the other, and only proceed to execute the othercode...
once the second sound has completed playing?
Thank you in advance!
EDIT: following @Julian's response Hello - for clarification, here is the code I am using to queue items and play them. While the queued items indeed play in sequence, the subsequent function/code executes concurrently with the sound rather than waiting for the sound(s) to finish.
function playSequence(soundArray) {
soundArray[0].play();
soundArray.forEach(function(element, index, array) {
if (soundArray[index + 1]) {
soundArray[index].onStop.addOnce(function() {
soundArray[index + 1].play();
}, this);
}
});