[DEMO] Dynamic Fade In & Out using SM2 background audio
Jul 25, 2015
Ok, this one was a must do for me during the design stage of what never became my Articulate Guru 15 entry. I had long ago been able to use Soundmanager in projects where background audio was required, but never really felt like I had complete control.
This little demo works around some of the well-reported limitations using dynamic fades controlled by a single variable (well, more like...two). So everytime you want to lower the volume or completely turn it off you'll be able to do it by changing the value of just one variable.
View Demo
Story file - See attachment below.
INSTRUCTIONS (i.e. How to edit the example file for own use)
1) Publish the story once and copy the folder generated by the webobject (should be named 6ot4STUqXpR) somewhere on your computer.
2) In your new folder, replace 6ot4STUqXpR/audio/main.mp3 with the audio file of your choosing.
3) Then go back to the source story and remove the webobject from slide 2.1 and add it again pointing to the index.html of the folder you copied (and edited in step 2).
4) Republish the story - a new webobject folder will be created (with a different 11 character ID). Note that down.
5) Replace all instances of '6ot4STUqXpR' with the new ID in :
a) the 1st slide trigger in Slide 1.1
b) layer trigger inside Layer 'Audio Play' on the Master slide
6) Remove unnecessary clutter (play/pause buttons etc.) - they are only used as an example. Or you can keep them if you require user intervention.
Finally, you can control play by incrementing variables audioPlay, audioPause, audioResume, audioStop and...
audioVolume: this last one can be set to 0 for complete fade out, 100 for fade in, or any other number in between - the script automatically decides whether it should fade in or out depending on the previous audioVolume value.
Hope you like it.
Enjoy,
Alex
15 Replies
OMG I love this Alex. It's too bad you didn't get it done for the Gurus.
Great work Alexandros.
I was just exploring source file that you have provided. I did not understand, what purpose is behind variables "
audioPause
,audioPlay
,audioResume
andaudioStop.
I guess these variables are not making any significant difference. Please correct me if I am wrong.Again Very great work, really like it.
@Nancy
What I like about this is that with a little bit of extra coding you can potentially define the duration of each fade too.
@Parashuram
They are. They fire the layer that corresponds to an action via listener triggers. The value in them does not matter though, and you could combine in just one variable if you want.
Very nice.
How do you reference the volume via trigger on a slide? For example, If I wanted to fade music to zero beginning at 5 seconds before the end of voice narration. What reference do I use to lower the vol?
I've tried using audioVolume, but it's not working. What am I missing?
Hi Mike,
If you set the audioVolume variable equal to a different value than what it currently has, it should run a sequence that increments/decrements the actual volume (audioVolumeOld) to the percentage value that you set (you should notice audioVolumeOld running through an iteration as soon as you click outside the textbox).
I've set the trigger as, "Change value of audioVolume to x when textbox loses focus" because of the actual textbox, but you can use any event you like.
But make sure you're not running or previewing this locally as the functions are being run in JS.
Vine demo of the initial test (functionally identical to the story attached here).
The 1% increment/decrement is currently set to constantly occur every 50ms (but you can change that value to get a faster/slower fade in the Audio Fade In Out Master Slide Layer's JS trigger (Lines 4 & 6).
Let me know how it goes.
Hope this helps,
Alex
Ah yes. =)
Muchas Tacos! Was confused there for a moment. Has anyone tried this for multiple audio files (.mp3)? Say...based on slide type (Title Only, Title with Content, etc.)?
I imagine needing to stop the audio, then call the object again using a different .mp3 file.
Thanks again Alex. =)
This was designed to work with only one background audio file.
You'll need to change some code (on the Masters) around to accomodate 3 (or more) different background audio files, but it's perfectly doable.
Also, inserting the additional mp3's in your folder should still occur in Step 2 as described above, so by doing so it means you will have to redo Steps 3-6 again (no way around that I'm afraid). This is also true if you just want to simply replace that 1 audio file the template is designed for.
I'm very interested to see how you'll be using this and provide some potential feedback in the process (screenshots mostly welcome).
Thanks,
Alex
Alex,
This is beautiful. But what am I missing? I need to change the rate and can't find the Audio Fade In Out Master Slide Layer's JS trigger.
Hi Charlie,
Here's the screenshot of the layer and the exact number you need to change.
The number is milliseconds, so if you need to Fade In/Out faster, you should go with a number lower than 50 (but not less than 1).
You can also have different speeds for each type (the first "50" Fades Out, the seconds one Fades In).
Hope this helps,
Alex
Thanks for the quick response. I don't know how I missed that. It works beautifully.
Have you found a way to work around the Chrome 70 autoplay block?
I cannot get the music to autoplay on Chrome 70 even if I add the LMS site to the whitelist and allow autoplay of audio. Local playback is no issue.
We need to republish our courses to HTML5 Only. When I republish as HTML5 the course breaks and won't run. Any fixes for HTML5?
Hi Charlie!
What do you mean it won't run? What happens exactly?
I think the quickest way to resolve this issue is to have our Support Team take a look. You can submit a case here.
Hi Alex,
I need to republish this course as HTML5 only. When I do that now in Storyline 360 the volume fade no longer works. Is there something I need to update?
There are 2 things I would check.
1) Check whether the folder generated by the webobject has changed. If so, the reference inside the js triggers should change as well (see OP for detailed steps on how to do this).
2) For some unknown reason, sometimes a variable does not fire when using a "When timeline starts" event trigger. This is a well known bug that has carried over from the SL2 version. To get around this I use a "When timeline reaches 0.1sec" event in place - that works every time.
Hope this helps,
Alex
This discussion is closed. You can start a new discussion or contact Articulate Support.