Forum Discussion
Articulate Storyline 360- Music across specific slides - how to stop it?
Hi all.
I know there have been a couple of threads on this topic. The ones I see are more than a couple of years old, from what I can tell, so I am hoping to get a 2022 perspective if possible. I have background audio that I want to initiate on slide 2 and then continue to play until the learner reaches a specific target layer of say, slide 15.
From previous instructions posted on this topic, I have managed to execute the first part of this; my background music is indeed starting when it's supposed to, and continuing across subsequent slides (Woo!, because I really don't know javascript).
The issue I can't yet solve is how to get it to STOP when we reach the target slide. Below is my initial "execute javascript" trigger.
function add_line() {
var line = document.createElement("audio");
var head=document.getElementsByTagName('body')[0];
line.type = "audio/mp3";
line.src="story_content/audio_files/Jeopardy 3 Minute music Mixdown JHenry.mp3";
line.id="bgSong";
line.autoplay = true;
line.loop = true;
head.appendChild(line);
}
if(document.getElementById('bgSong')==null){
add_line();
var audio = document.getElementById('bgSong');
audio.volume = 0.1;
}
Can anyone give me the approach and steps to solve this?
- Jürgen_Schoene_Community Member
this javascript should stop the audio
if(document.getElementById('bgSong')!=null){
var audio = document.getElementById('bgSong');
audio.pause();
}- JamesWHenryCommunity Member
Hi Jürgen .
Thanks for the quick reply!
Where in this would I insert the actual audio file name? Or is it not
necessary?James
ᐧ
- JamesWHenryCommunity Member
Actually, Jürgen , never mind. I applied your recommended script and it works. Thanks so much! The music indeed stops at the correct trigger (reaching a certain slide and layer).
One other small issue - the music itself is a 3-minute audio which I don't want to play more than once. It is meant to serve as a timer for completion of the tasks.
However, it seems to be automatically looping with whatever programming I have set up in Storyline. How can I stop it from playing more than once?
Here are my two javascript triggers cuirrently set up in Storyline to initiate the music:
TRIGGER 1
function add_line() {
var line = document.createElement("audio");
var head=document.getElementsByTagName('body')[0];
line.type = "audio/mp3";
line.src="story_content/audio_files/Jeopardy 3 Minute music Mixdown JHenry.mp3";
line.id="bgSong";
line.autoplay = true;
line.loop = true;
head.appendChild(line);
}
if(document.getElementById('bgSong')==null){
add_line();
var audio = document.getElementById('bgSong');
audio.volume = 0.05;
}TRIGGER 2
var audio = document.getElementById('bgSong');
audio.src="Jeopardy 3 Minute music Mixdown JHenry.mp3";
audio.load();
audio.play(); - Jürgen_Schoene_Community Member
change
line.loop = true;
to
line.loop = false;
but TRIGGER 2 has a problem
audio.src="Jeopardy 3 Minute music Mixdown JHenry.mp3";
why do you set the onother src path like in TRIGGER 1?
if you only want to start the audio, thenif(document.getElementById('bgSong')!=null){
var audio = document.getElementById('bgSong');
audio.play();
} else {
console.error( "audio not defined" );
}should be better
BUT: are both TRIGGER on different slides?
if yes - do you have enabled "resume" on the player settings?
if yes - you have no audio, when the slide with TRIGGER 1 is not visited before TRIGGER 2 is used
- JamesWHenryCommunity Member
Hi again Jürgen -
. I also didn't quite understand why I needed the 2 separate triggers - I was just following the exact step-by-step of what another poster said to do on this issue, or so I thought. I looked at different people's solutions and some of them were slightly different from others. So now it's a bit of a fog to me.
(I tried disabling the 2nd trigger once, but that seemed to break the functionality of the music either playing or stopping- I forget which.)
Do I not need the 2nd trigger, or does the 2nd trigger simply need to be modified?
Both triggers appear on the same slide (Slide 2,), and don't appear anywhere else in the course.
James
- Jürgen_Schoene_Community Member
you don't need two trigger
initialize and play audio
if(document.getElementById('bgSong') === null){
var audioFileName = "Jeopardy 3 Minute music Mixdown JHenry.mp3";
var audioVolume = 0.05;
var audioNode = document.createElement("audio");
audioNode.id = "bgSong";
audioNode.type = "audio/mp3";
audioNode.src = "story_content/audio_files/" + audioFileName;
audioNode.volume = audioVolume;
audioNode.loop = false;
audioNode.autoplay = true;
document.body.appendChild(audioNode);
var audio = document.getElementById('bgSong');
audio.play();
}i have reorganized the script a bit - so it should be more readable
stop audio
if(document.getElementById('bgSong') !== null){
var audio = document.getElementById('bgSong');
audio.pause();
audio.currentTime = 0;
}pause audio
if(document.getElementById('bgSong') !== null){
var audio = document.getElementById('bgSong');
audio.pause();
}play audio
if(document.getElementById('bgSong') !== null){
var audio = document.getElementById('bgSong');
audio.play();
} - JamesWHenryCommunity Member
Hi again. I replaced my current initialization script/trigger with your "initialize and play audio" script.
I also deleted my 2nd script
TRIGGER 2
var audio = document.getElementById('bgSong');
audio.src="Jeopardy 3 Minute music Mixdown JHenry.mp3";
audio.load();
audio.play();When publishing, there is no audio whatsoever.
Then, I added your "play audio" script as an additional trigger (both triggers on Slide 2).
Published, and no audio is heard.
I think I need a more granular step-by step in order to get this right and to know what to put where and what not to include.
Also, I was a little confused about why you included both an "initialize and play audio" and also a "play audio" script.
I want to do 3 things
1. initialize and play a 3-minute audio (from slide 2), continuously throughout progress through the slides.
2. Stop that audio when user reaches a target slide. Meaning the user has reached the slide before 3 minutes.
3. Don't loop the audio that was started on Step 1. It naturally ends after 3 minutes because it is a 3-minute audio.
So I don't need to pause the audio or restart it at any time, once it has started.
Thanks for your responses and time, Jürgen. I know it's not helpful that I don't know javascript, lol.
James
- JamesWHenryCommunity Member
UPDATE- the audio functionality is now working perfectly as I wanted. Your information about changing loop to 'false' was all I needed.
THANKS Jürgen !!!
- JamesWHenryCommunity Member
One other important thing I didn't mention- I'm not using the Storyline player for this course. I have disabled it and am using my own "Next" buttons. So I am not using the "resources" section of the player, as some solutions for this issue assume or recommend.
- MathNotermans-9Community Member
The resources solution as mentioned in other posts doesnot need to use the player. The scene with the resources and the player will not be visible in the final published output. It is just used to easily set the resources/mp3 files to the proper path so Storyline always can find it.
- JamesWHenryCommunity Member
OK - UPDATE for anyone following this thread.
I have the music working exactly as I'd hoped, across slides and stopping when it's supposed to. Working perfectly. Woo hoo!
Export it from Storyline via "web"-- then I copy/paste the background music file to the exported Story Content folder. When I launch the story file-- again, it works perfectly.
HOWEVER... I have tried numerous times to export this to TALENT LMS - where the full course (of which this is one module) lives. But on TalentLMS, the MUSIC doesn't play, ever.
Before zipping the file, I copy/paste the background music file into the storyline output folder. I've tried to additionally paste it to the story_content folder and also the LMS folder.
Nothing works. When I launch the game on Talent LMS, all my other audio sfx sounds work EXCEPT the background music audio.
Anybody know TalentLMS and what I am missing?
- Jürgen_Schoene_Community Member
do you use scorm? if yes - has you updated "imsmanifest.xml" ?
- Jürgen_Schoene_Community Member
do you get an 404 error for the background music in the browser console (-> F12)