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
Hi Keith,
It's not code that I can assist with, but if you'd like folks in the community to take a look can you share the code snippet that you included here with them? Also you said you were editing it in the story.html file and that's what is created when you publish for Web but you likely need to publish for LMS if that will be where you're ultimately uploading the published output.
- KeithRambertCommunity Member
I just tested it on SCORM cloud and the audio plays along with the narration just fine.
- KeithRambertCommunity Member
OK so the background music tag works in Chrome and Firefox but not in IE.
- KeithRambertCommunity Member
Fixed with the Compatibility setting in Cornerstone.
Very good Keith - thanks for keeping us up-to-date on your testings/findings.
Hello Anne and welcome to E-Learning Heroes :)
Not sure if Jackson is still subscribed here or not as this thread is a bit dated, but thanks for sharing your file so that the community can take a peek and assist.
If you do not hear back soon, you are welcome to reach out to the user directly via the 'Contact Me' option on the user profile.
- AlexandriaLairdCommunity Member
Hello Anne,
I am by no means a JavaScript expert however, I have been working on applying this process to one of my own courses. Based on previous conversations in this thread I was able to get it working on my own course with this code:
//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+"NAME OF SONG HERE.mp3";
audio.load();
audio.play();Using the code above at the JavaScript executed on the first slide has been working for me. You should be able to copy and paste it into your own trigger on that first slide. Make sure you edit the NAME OF SONG at the bottom. Additionally in your "location" trigger you only need to start at story_content. You do not need to include all of the information before that part. So the text in your location trigger should only be: story_content\WebObjects\6RU7elBBAGE
Hopefully these changes may be able to help you!
~Alex
- AnneLobascherCommunity Member
Hi Alex,
Thanks so much for your help.
I have put your instructions into my file to try again but still not working. Just a couple of questions:
- In the location variable, should the path contain backslash or forward slashes. When I looked at Jackson's example, he had forward slash and you have back slash, so does it matter?
-
- Once I publish to get the web object number and copy to the variable, I save the file but if I publish again to play, the web object number will change, so I'm wondering if that is my problem ie. when I publish to test the audio, I am changing the web object number to the variable and therefore it is not working. If so, how do I start the project to test for the audio?
Hope I make some sense! Thanks for your help :)
AnneConfidential communication
Westpac Banking Corporation (ABN 33 007 457 141)
Westpac Institutional Bank is a division of Westpac Banking Corporation - AndersonRumuyCommunity Member
Hi Alex,
After tried this code, I thought there is a better way to add background music
I think manny of us also use this methode so I prefer this one because more simple
Edit the output of Course Publish and add this JS:
<audio src="1.mp3" id="bgSong" preload="auto" autoplay loop></audio>
1. Right click on the html5 & open with Notepad or Notepad ++
2. add this js into html5 output right between the <body> and <!-- 360 --> like this picture below:
3. Save & exit
And don't forget :
1. to change the "1.mp3" to your audio file name. Mine is 1.mp3
2.paste "1.mp3" into the publish output folder where you edit the hmtl5
-Anderson-
Glad to hear it Anne - I did want to let you know that replying to the forums via e-mail attaches your signature. You are welcome to pop in and edit if needed.
- AlexandriaLairdCommunity Member
Hello Anne,
For the location variable you are correct, it should be the forward slashes (what I copied there was incorrect). You should correct the slashes to match Jason's example.
Secondly, I am not sure why the web object is changing. I believe once you have put it in and publish the first time it should remain named the same. I created mine and then published it many times to test it and have had no problems with the location needing changed.
A few other things to check:
- Make sure your song name in the script on your first slide matches the song file name exactly in the file you created the web object.
- Double check your location variable is accessing the correct web object and that the file name is an exact match.
I know this process can be frustrating, it took me quite a while to get mine working properly, but it is definitely worth all the effort once it works! Hopefully this helps!
~Alexandria
- LywandaHeldCommunity Member
This works for me (!!!) within our LMS (Saba). Thanks so much!
Related Content
- 12 months ago
- 3 years ago