Forum Discussion
Background Music Demo
I made a demo featuring background music that goes through the whole course (doesn't change from slide to slide). The user can chose from four songs to listen to and can adjust the volume, and the song continues playing through every slide and loops when it completes. I've also added instructions on how to make this work to the module.
I don't know whether someone else has already posted something like this (I couldn't find anything), but hey if so here's one more!
-------
I've put together a second demo that shows a different way to do this. This second version performs the same actions as the first one, but without needing to edit the output files every time you publish! It saves a lot of headaches when you need to edit something in the course because now you don't have to drop the music files into the output folder and you dont have to edit the html file every time you publish!
I've also attached the second version .story file. Its called Background_Music_Version_2.story.
If anyone needs help getting either versions of this to work I'm more than happy to assist :)
203 Replies
- JacksonHamnerCommunity Member
Hi Jane, sorry it took so long to respond:
I had never considered the returning to course or jumping around the menu! I think that the easiest way to get around this is to drop the javascript triggers into the slide master so they run on every slide in the background.
The problem with that though, is that if it runs on every slide then the song will restart every time the trigger fires. BUT I think there is a way around this!
So firstly, any of the javascript triggers you are using should be pasted into every slide master main page that you use in the course. That way no matter where the learner jumps in the music should continue start playing.
Secondly, we're going to need to edit the javascript so that it checks to see if there is already music playing before starting this song. This will help us avoid the problem of the song restarting every time the trigger runs.
You'll want to change this:
//load the scripts dynamically into the head of the document
function add_line() {
var line = document.createElement("audio");
var head=document.getElementsByTagName('body')[0];
line.type = "audio/mp3";
line.src="";
line.id="bgSong" ;
line.autoplay = true;
line.loop = true;
head.appendChild(line);
}
//but we only want to add these once!
if(document.getElementById('bgSong')==null){
add_line();
var audio = document.getElementById('bgSong');
audio.volume = 1.0;
}
var player = GetPlayer();
this.Location= player.GetVar("location");
var audio = document.getElementById('bgSong');
audio.src=Location+"SONGNAMEHERE.mp3";
audio.load();
audio.play();To this:
//load the scripts dynamically into the head of the document
function add_line() {
var line = document.createElement("audio");
var head=document.getElementsByTagName('body')[0];
line.type = "audio/mp3";
line.src="";
line.id="bgSong" ;
line.autoplay = true;
line.loop = true;
head.appendChild(line);
}
//but we only want to add these once!
if(document.getElementById('bgSong')==null){
add_line();
var audio = document.getElementById('bgSong');
audio.volume = 1.0;
}
var player = GetPlayer();
var audio = document.getElementById('bgSong');
this.Location= player.GetVar("location");
if (audio.duration > 0 && !audio.paused) {
// If song is playing and not paused then do nothing
}
else {
audio.src=Location+"Happy.mp3";
audio.load();
audio.play();
}This should check if the audio is playing or not, and if not then it will load the song again.
I haven't tested this yet and unfortunately I can't get around to it until later this week probably, so this is just a theory so far. I hope that it works though! Let me know if there's any problems with this and I can try to help as much as I can.
- JaneJordan1Community Member
H
i Jackson All I can say is you are a GENIUS ! it works thank, you thank you
Jane
*Jane Jordan*
- JacksonHamnerCommunity Member
Scooore, glad it ended up working!
I'll update the example files to include this information when I get the chance :)
- ChristiePollickCommunity Member
Great work, Jackson, and thanks so much for helping Jane get to where she needed to go! :)
- JaneJordan1Community Member
Hi five to all of the great help you guys give the community - no question is too silly and all questions are answered.
Well done and thank you
Sent from my iPhone
- ChristiePollickCommunity Member
How kind of you to say, Jane, and we think this community is something really special, too! We're so fortunate that everyone generously contributes their various skills and experiences to benefit one another and help everyone succeed... pretty darn cool, if you ask me! :)
- JacksonHamnerCommunity Member
Hey Jane,
Unfortunately I don't know of a way to interact with the storyline player in that way. To my knowledge its not possible to really interact too much with the built in play/pause button, seekbar, etc.
- JaneJordan1Community Member
Yep thought so
Sent from my iPhone
- ChristiePollickCommunity Member
Many thanks for the follow-up, Jackson! Hope that answers your question, Jane, or perhaps others could share some insight if they have an idea you could try. :)
Hi Jane! Glad that Jackson was able to assist you up until this point :)
Thank you Jackson! Great thread for others in the community as well.
- ChristiePollickCommunity Member
Hi, Jane -- Unfortunately, as it appears you replied via email, your image/screenshot did not come through to the thread. From within the thread itself, all you will need to do is click on the 'Insert an Image" icon (highlighted in the screenshot below), or you may use the ADD ATTACHMENT button in the bottom left corner. Hope that helps! :)
Hi Jane! Yes, that warning is due to viewing locally. I would advise to test in the intended published environment. If you are not ready to load to your LMS, you could utilize SCORM Cloud if you wish.
- ChristiePollickCommunity Member
Hi, Jane -- Just in case you wanted to check it out, here is some additional info on Publishing and Sharing Storyline 2 Content. Please let us know if you have any other questions! :)
- RyanGranvilleCommunity Member
Just a message to say thanks a lot Jackson and the community! This thread helped me a lot!
Related Content
- 12 months ago
- 3 years ago