hypeDocument.unloadSound
resets the audio element and removes it from the DOM given a HTMLAudioElement to kill.
You will only need this if you are concerned with garbage collection.
/**
* hypeDocument.unloadSound 1.0
* @param soundname
*/
hypeDocument.unloadSound = function(audioRef){
if (!hypeDocument.hasOwnProperty('_sounds')) return false;
for(var id in hypeDocument._sounds) {
if (audioRef === hypeDocument._sounds[id]) {
var elm = hypeDocument._sounds[id];
elm.src=''; elm.load();
elm.parentNode.removeChild(elm);
delete hypeDocument._sounds[id];
}
}
}
Usage:
Given you have a “soundfile.mp3” in your library and loaded it using HypeDocument.loadSound this function will remove the instances by reference. You need to store the reference todo so.
var snd = hypeDocument.loadSound('soundfile');
//makes no sense but let's unload it directly again :-)
hypeDocument.unloadSound(snd);