I am trying to loop through a bunch of sound files in SoundManager2 and play them at various points in time. The code below takes a songArray that looks like this, with the "note" consisting of a sound file and a duration for how long to play that sound file:
var songArray = [[null],[["clarinet_e4.mp3",1],["clarinet_a4.mp3",1]],[null],[null],[null],[null],[["clarinet_c4.mp3",1]],[["clarinet_c5.mp3",1]],[null],[["clarinet_ab4.mp3",1]],[["clarinet_f3.mp3",1]],[null],[["clarinet_g4.mp3",1]],[["clarinet_d5.mp3",1]],[null],[null]]
It goes through each X in the array and plays the sounds found for the given X. It then stops the sound after a time given by the duration. The code runs perfectly except that when a sound is stopped, it gives a popping noise just at the end of the song.
function playSong(X) {
playSongNotesAtXValue(X);
window.setTimeout(function() {
X++;
if (X >= theSong.songArray.length) {
X = 0;
}
playSong(X);
}, (30/theSong.tempo)*1000)
}
function playSongNotesAtXValue(X) {
var columnToPlay = theSong.songArray[X];
if (columnToPlay[0] != null) {
for (i = 0; i < columnToPlay.length; i++) {
var note = columnToPlay[i];
soundManager.play(note[0],{volume:30});
window.setTimeout(function() {
soundManager.stop(note[0]);
}, (note[1]*30/theSong.tempo)*1000);
}
}
}
Any ideas for what could be wrong?
P.S. We have tried it on the latest version of Safari, Chrome, and Firefox.