Turning Music on and off

M

Mike Scholl

I have a Ballet School site on which I have some background music

I have been implementing this by having an invisible frame in which I have a
page with a <embed src="mytune.mp3"> tag

To turn it off I simply replace the document in this frame with one without
the embed tag.

I would rather do away with the frames and use javascript to control the
music.
so my current solution is to have an embed tag to the music file (as before
but with a name so I can change it), a playSound and stopSound function to
turn it on and off and a startmusic function which is the onload event of
the body to start it playing if it hasn't been started already

My problem is that with my previous solution the music carried on playing to
the end of the piece even if the user changed pages (the document with the
embedded music carries on playing)
Now if the user chooses a menu option the page is reloaded the onload event
startmusic() decides not to start it playing again.

Is there a way I can leave the music playing when the page changes?

Mike

This is my code

var visitordata = new Cookie(document, "music_state", 240,"/");
var loadedcookie = new Cookie(document, "isloaded", 1,"/");

function playSound() {
visitordata.muson = "T";
visitordata.store();
self.document.swanlake.play() ;
self.document.swanlake.hidden = false;
}

function stopSound() {
visitordata.muson = "F";
visitordata.store();
self.document.swanlake.stop();
self.document.swanlake.hidden = true;
}

function startmusic()
{
var loaded
if (!loadedcookie.load()) {
loaded = false;
}
else
{
if (loadedcookie.loaded == null) loadedcookie.loaded == false;
loaded = loadedcookie.loaded;
}
if (!loaded)
{
if (!visitordata.load())
{
visitordata.muson = "T";
}
if (visitordata.muson == null ) visitordata.muson = "T";

if (visitordata.muson=="T" && loaded)
{
playSound();
}
visitordata.store();
loadedcookie.loaded = true;
loadedcookie.store();
}

}
//-->

</script>

</HEAD>
<BODY onload="startmusic()">
<EMBED NAME="swanlake" SRC="s_lake9.mp3" LOOP="FALSE" AUTOSTART="FALSE"
HIDDEN="false" width="144" height="16" MASTERSOUND align="right">
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,187
Members
46,728
Latest member
FernMcmull

Latest Threads

Top