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 :)
- JacksonHamnerCommunity Member
Hi Jane,
Would you be able to share your .story file so I can see how you've set up your triggers? That would help me pinpoint the error much easier.
I can see in your output files that the trigger adding the <audio> tag is working, but the trigger adding the src value for the audio tag didn't since the src="" is still empty. I would start by looking at that trigger to see if there is a problem with the code.
Since you are only using one song I would just hard code the song name into the audio tag when its initialized so you don't have to set up additional triggers. If you can share your .story file I can help you set up the script to do this
- JaneJordan1Community Member
Hi Jackson
Here is the output file.
Jane
- ChristiePollickCommunity Member
Hi, Jane! I see that you replied to Jackson via email, and I wanted to note that if you try to add an attachment when replying via email, unfortunately, it will not appear here in the thread to be accessible.
I also wanted to clarify that what Jackson would like to see is the .story file (or the source file itself) rather than the published output file, and the easiest way to share that would be to stop over into the forum/the thread, and click on the grey "ADD ATTACHMENT" button in the bottom left corner of the reply box. You will be able to browse for your file from there, and it will appear here in the thread. Please let us know if you have any other questions! :)
- JaneJordan1Community Member
Hi Jackson
here is my source file - if you wouldn't mind taking a look at what is missing to make the background music JS work.
Is it also possible to have the java script not execute on one slide or scene in the project, I will have video inserted and it already has background music?
thank you much appreciated
Jane
Thanks for your continued assistance Jackson.
- JaneJordan1Community Member
- ChristiePollickCommunity Member
You got it, Jane! I was just about to clarify that we were basically just hoping to see the .story file that you work in before you hit the Publish button, and that you should see a small, pinkish-purple "a" icon with your file name where you have saved the file (probably on your C: drive). Glad you got it sorted out! :)
- JaneJordan1Community Member
thanks Christie - bit dozy its the middle of the night here is Oz
- JacksonHamnerCommunity Member
Thanks Jane!
So firstly, the location variable goes back too far, the current one is:
"C:\Users\Jane\Documents\My Articulate Projects\test background music - Storyline output\story_content\WebObjects"
and all you need for that variable is: story_content\WebObjects\6VUFHlYBLQO
The last bit, the 6VUFHlYBLQO part, can be found in the WebObjects folder after you publish your storyline file. If you ever add any additional songs or change the song that you included in the course you will need to find that folder again and update the variable with the new random string of numbers and letters.
Secondly, the trigger setting the song to start playing is missing. In your case, since it is just a single song, I would just lump that trigger into the same javascript trigger you already have to make it easier.
Use this trigger:
//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();and replace "SONGNAMEHERE.mp3" with the real name of the song. The bold part of the script is the new part and you can add it to your trigger. This should get your music starting when the timeline starts.
Let me know if you run into any more issues! I hope this helps :)
- JaneJordan1Community Member
Wow thank you so much for your help Jackson I will try that out asap - cheers and much appreciate your time
Sent from my iPhone
- ChristiePollickCommunity Member
Understandable, Jane -- happens to us all on occasion! And Jackson, you are a wiz as always, so thanks for all of the assistance you have provided! :)
- JacksonHamnerCommunity Member
Haha, no problaemo guys :)
Its cool seeing other people using this!
- JaneJordan1Community Member
Hi jackson
Couldn't sleep so I got up and tried your solution - I must be missing a step as I couldn't get the music to play, have attached the source file and screen shots of my file locations and web object content and location. hoping you can help thanks Jackson