Hi alebot,
you were quite near, I guess!
I simply copied your code into two passages , 1 with other mp3 and without loop, see below.
I did not change the story javascript, just added to the passages.
So effect is:
- Opening the story: music.mp3 sounds nicely.
- Switching to Next passage: effect.mp3 'tata's immediately, and music still plays.
Start passage: (your code unchanged)
Check the tune
<script>
var audio= document.createElement('audio');
audio.src=
'music.mp3';
audio.loop = true;
audio.play();
</script>
[[Next]]
The 'Next' passage contains the same code slightly changed:
Effect Sound bouncing in?
<script>
var audio= document.createElement('audio');
audio.src=
'effect.mp3';
audio.loop = false;
audio.play();
</script>
And Tune still to hear?
[[Start]]
Does this work for you?
So if you want to play the same sound on really 'each new passage', then it might work without copying the script code to each passage:
Instead, create one extra passage with the <script>...</script> snippet inside and do add the tag header to the passage.
Then this script should play on any passage you switch to in this story.
*BUT* - as I see while trying that - this will make the effect.mp3 also play on the Start passage of the story, To avoid that, the 'header' tagged passage should look like this (assuming the start passage of the Story is named 'InTheMorning')
Passage with any name but tagged with: header
(if: (passage:)'s name is "InTheMorning")[\
(set: $playSound to false)]
(else:)[(set: $playSound to true)]
(if: $playSound)[
<script>
var audio= document.createElement('audio');
audio.src=
'effect.mp3';
audio.loop = false;
audio.play();
</script>
]
Instead of the (if: $playSound)[.....] a simple $playSound[....] would be sufficient.
So, finally I hope, this answer still comes just in time for your story telling, as it was already posted 3 days ago.
Regards