It looks like you're new here. If you want to get involved, click one of these buttons!
macros['playsound'] = macros['stopsound'] = {
handler: function(place, macroName, params, parser) {
var audio;
if(macroName == 'playsound') {
audio = document.createElement("audio");
audio.setAttribute('id', params[0]);
$("#passages").append(audio);
if (audio != null && audio.canPlayType)
{
audio.src = params[1];
audio.volume = 0.1;
audio.play();
}
}
if(macroName == 'stopsound') {
audio = document.getElementById(params[0]);
audio.pause();
}
}
};
Tada! Written from scratch! And I know how everything works! Woo! I'm smert. So as you can see, I'm appending the audio element to the DOM. We can create audio elements dynamically with argument generated id names, and then stop those whenever we want. Problem is, I'm appending to #passages, which uh... gets wiped every time the history state changes. So the sound goes poof. Is there a 'correct' place to put elements that should endure across passage transitions? Or am I going about this the complete wrong way?