PDA

View Full Version : Music Off delay in IE 7- HELP



webill
06-30-2008, 03:57 PM
Hi folks, I have a code for music on/off that finally works in all browsers but in IE7 to turn off the sound I have to click the off button many times before it quits the music....
Can any good soul help me out on this one?
Hereafter the code, thanks a lot!

<body id="bodyMain" onload="javascript:soundCtrl('on')">
<script language="javascript" type="text/javascript">
var soundSource="../audio/tequila.mp3";
function soundCtrl(onoff) {
if(onoff == "off") {
var sound = el("bgsound");
if(sound)
document.getElementById("bodyMain").removeChild(sound);
}
else if(onoff == "on"){
if(el("bgsound")) return;
var sound = document.createElement("embed");
sound.setAttribute("src",soundSource);
sound.setAttribute("hidden",true);
sound.setAttribute("autostart",true);
sound.setAttribute("id","bgsound");
document.getElementById("bodyMain").appendChild(sound);

}
}
function el(id) {
var el = document.getElementById(id);
return el;
}
</script>
HTML
<a href="#" onclick="soundCtrl('off')">shut up&nbsp; |</a>
<a href="#" onclick="soundCtrl('on')">play on</a>

magicyte
07-01-2008, 11:06 PM
Try the old-fashioned way:

<bgsound id="bg" src="some_music_title.wav" volume="0"></bgsound>

This may help.

-magicyte

webill
10-07-2008, 03:32 PM
Thank for the answer but how do you stop it. I need to have a on /off button

magicyte
10-08-2008, 12:45 AM
To stop it, set the volume to -10000. To do this, here:

document.getElementById('bg').volume = "-10000";

Any other questions, comments, or requests? You know what, here:


<a href="#" onclick="document.getElementById('bg').volume = '-10000';">OFF</a>|<a href="#" onclick="document.getElementById('bg').volume = '-10000';">ON</a>

These up here ^^^ are the functions you need. However, I got this stuff from this:


function BGMSTOP(){
if (systm == "C"){
BG.src = "test001.mid"
BG.volume = -10000
}else{
document.embeds[0].stop()
}
}

function BGMSTART(){
if (systm == "C"){
BG.src = "Soul_Food.mid"
BG.volume = 0
}else{
document.embeds[0].stop()
document.embeds[0].play(true)
}
}

You can use excerpts of code from here for your needs.

-magicyte