It looks like you're new here. If you want to get involved, click one of these buttons!
var audio = document.createElement('audio');
audio.setAttribute('id', 'nowplayingbirds');
audio.src = 'music/birds.mp3';
audio.loop = true;
$("body").append(audio);
audio.play();
var audio = document.createElement('audio');
audio.setAttribute('id', 'nowplayinglaughing');
audio.src = 'music/laughing.mp3';
audio.loop = true;
$("body").append(audio);
audio.play();
var audio = document.createElement('audio');
audio.setAttribute('id', 'nowplayingdripping');
audio.src = 'music/water_drops.mp3';
audio.loop = true;
$("body").append(audio);
audio.play();
var audio = document.createElement('audio');
audio.setAttribute('id', 'nowplayingviolin');
audio.src = 'music/SadViolin.mp3';
audio.loop = true;
$("body").append(audio);
audio.play();
var audio = document.createElement('audio');
audio.setAttribute('id', 'nowplayingcrying');
audio.src = 'music/crying.mp3';
audio.loop = true;
$("body").append(audio);
audio.play();
var audio = document.createElement('audio');
audio.setAttribute('id', 'nowplayingnight');
audio.src = 'music/night.mp3';
audio.loop = true;
$("body").append(audio);
audio.play();
var audio = document.createElement('audio');
audio.setAttribute('id', 'nowplayingdarkness');
audio.src = 'music/darkness.mp3';
audio.loop = true;
$("body").append(audio);
audio.play();
var audio = document.createElement('audio');
audio.setAttribute('id', 'nowplayingpiano');
audio.src = 'music/piano.mp3';
audio.loop = true;
$("body").append(audio);
audio.play();
And I have a passage set up with the tag, stylesheet, with the following inside. This passage tells the sounds to stay quiet until I give them the command.
<div style="display: none;"><img src="!@#$" onerror="$('#nowplayingbirds').animate({volume: 0}, 0);" /></div>
<div style="display: none;"><img src="!@#$" onerror="$('#nowplayinglaughing').animate({volume: 0}, 0);"/></div>
<div style="display: none;"><img src="!@#$" onerror="$('#nowplayingdripping').animate({volume: 0}, 0);" /></div>
<div style="display: none;"><img src="!@#$" onerror="$('#nowplayingviolin').animate({volume: 0}, 0);" /></div>
<div style="display: none;"><img src="!@#$" onerror="$('#nowplayingcrying').animate({volume: 0}, 0);" /></div>
<div style="display: none;"><img src="!@#$" onerror="$('#nowplayingnight').animate({volume: 0}, 0);" /></div>
<div style="display: none;"><img src="!@#$" onerror="$('#nowplayingdarkness').animate({volume: 0}, 0);"/></div>
<div style="display: none;"><img src="!@#$" onerror="$('#nowplayingpiano').animate({volume: 0}, 0);" /></div>
It's piano in particular that keeps playing even though I tell it not to.
Comments
To test if this is the case, if you swap the order of "darkness.mp3" and "piano.mp3" in your JavaScript, does "darkness.mp3" now play nonstop?
To fix it (and yes, haha, there are better ways, I'm sure!) if instead of... ...you write... ...then I think you might get the effect you're looking for, where it plays the audio, just silently, and when the audio volume is triggered, the browser doesn't start that music at the beginning of the MP3, but rather, at the point it would be were it playing all along. Is that right? If I'm misunderstanding whether or not that's the effect you want, let me know! One of those "easier, cleaner ways" you mentioned might be a good solution.