Forum Discussion
Background Music Demo
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.
- JaneJordan110 years agoCommunity Member
H
i Jackson All I can say is you are a GENIUS ! it works thank, you thank you
Jane
*Jane Jordan*
- JacksonHamner10 years agoCommunity Member
Scooore, glad it ended up working!
I'll update the example files to include this information when I get the chance :)
- JaneJordan110 years agoCommunity Member
Hi Jackson
Just as a side and its not a show stopper, is there any Java script which
would allow the music to pause and restart when the user pauses the button
on the playbar?Cheers
Jane