Firefox crashing when programming Audio element with Javascript
I'm programming a game, using setTimeout to iterate the game loop at a rate of 50 calls a second.
I'm using this sound code:
function createAudioStation (slots) {
var station = { slots: new Array(slots), slotsLimit: slots };
for (var index = 0; index < station.slotsLimit; index++) { station.slots[index] = { }; station.slots[index].element = document.createElement("audio"); document.body.appendChild(station.slots[index].element); }
return station; }
function loadAudio (station, file, volume, loop) {
file = file.substring(1, file.length - 1);
for (var index in station.slots) {
if (station.slots[index].element.src == "") { station.slots[index].element.autoplay = true; station.slots[index].element.src = file; station.slots[index].element.volume = 1; if (loop == 1) station.slots[index].element.loop = true; station.slots[index].element.index = index;
if (loop == 0) station.slots[index].element.onended = unloadAudio;
return; } } }
function killAudio (station) {
for (var index in station.slots) {
document.body.removeChild(station.slots[index].element);
station.slots[index].element = document.createElement("audio");
document.body.appendChild(station.slots[index].element);
}
}
function unloadAudio () {
this.src = ""; }