Forum Discussion
Need audio file to play throughout 2 slides
I have a 2-slide intro with background music that I use for multiple courses. In the previous authoring tool I was using I could place the audio file so that it covered both slides, but I don't see a way to do this in Storyline. I tried adding it as background audio, but I don't see any way to specify that it only play during those 2 slides rather than the whole course. Is there any way to do this?
Hi K_Dingman!
On the Slide 3, you could add a trigger to pause or stop the Background Audio.
For a smoother, less abrupt transition, you could use a series of timed triggers to reduce the volume of the Background Audio to zero and then stop it. This would reduce the volume to 90% for instance.
Or you could let Javascript handle it, but Player.BackgroundAudioVolume can't be set via SetVar() because it's a built-in player property, not a regular Storyline variable.
To achieve this, you'd need to create a 'bridging' variable, say 'Bgd_Volume' with a starting value of 100, and trigger Player.BackgroundAudioVolume to match any changes to it, like so:Then, this JavaScript could gradually reduce the volume over 5 seconds:
var player = GetPlayer(); var duration = 5000; // 5 seconds in milliseconds var interval = 50; // Update every 50ms for smooth fade var steps = duration / interval; var currentVolume = player.GetVar("Bgd_Volume"); var decrement = currentVolume / steps; var fade = setInterval(function() { currentVolume -= decrement; if (currentVolume <= 0) { currentVolume = 0; clearInterval(fade); } player.SetVar("Bgd_Volume", Math.round(currentVolume)); }, interval);
This trigger would be used to stop your audio when the volume hits 0:And if the user ever goes back to Slide 1 without restarting the course, and you want the music to play again, these triggers on Slide 1 would reset everything:
Hope that helps!
5 Replies
- Jonathan_HillSuper Hero
Hi K_Dingman!
On the Slide 3, you could add a trigger to pause or stop the Background Audio.
For a smoother, less abrupt transition, you could use a series of timed triggers to reduce the volume of the Background Audio to zero and then stop it. This would reduce the volume to 90% for instance.
Or you could let Javascript handle it, but Player.BackgroundAudioVolume can't be set via SetVar() because it's a built-in player property, not a regular Storyline variable.
To achieve this, you'd need to create a 'bridging' variable, say 'Bgd_Volume' with a starting value of 100, and trigger Player.BackgroundAudioVolume to match any changes to it, like so:Then, this JavaScript could gradually reduce the volume over 5 seconds:
var player = GetPlayer(); var duration = 5000; // 5 seconds in milliseconds var interval = 50; // Update every 50ms for smooth fade var steps = duration / interval; var currentVolume = player.GetVar("Bgd_Volume"); var decrement = currentVolume / steps; var fade = setInterval(function() { currentVolume -= decrement; if (currentVolume <= 0) { currentVolume = 0; clearInterval(fade); } player.SetVar("Bgd_Volume", Math.round(currentVolume)); }, interval);
This trigger would be used to stop your audio when the volume hits 0:And if the user ever goes back to Slide 1 without restarting the course, and you want the music to play again, these triggers on Slide 1 would reset everything:
Hope that helps!
- ThierryEMMANUELCommunity Member
Hello Jonathan_Hill
I’ve just used your little JS code in my latest project to lower the background sound to 0 at the end of three introductory slides and just before a character starts speaking. It flows really well. AND I used the AI assistant to tweak this code so that the background volume goes back up to 100 on the last two slides of the module. So, thanks for this handy little thing, which I’m keeping in my toolbox, in the little drawer labelled ‘JonHill’ where there are already others.
NB: please ignore the “Approved” label, which appears to be a platform bug. Neither I nor anyone else has actually approved this message so far 😅.
- Jonathan_HillSuper Hero
Glad to hear it was helpful ThierryEMMANUEL 👍
- ThierryEMMANUELCommunity Member
Yes, it's easy to do, and you're already halfway there, K_Dingman .
Just add a trigger at the end of the timeline of your second slide (or on the click of the “Next” button) that sets the built-in variable “Player.BackgroundAudioVolume” to 0. You won't hear the background audio anymore (until you reset the variable with another trigger if needed).
Plus :
Oh, I hadn't realised that Jonathan_Hill had drawn his gun a few seconds before me and hit the target dead centre with a single shot. 😁
- K_DingmanCommunity Member
Thank you both! I will try this!
Related Content
- 1 year ago
- 9 months ago
- 8 months ago
- 1 year ago