Give a site visitor the option to turn off a background sound fil

R

röös

When my site loads a MP3 file plays music, say four times. Can I add an icon
so that the visitor can turn it off at any time?
 
M

Mark Fitzpatrick

There aren't a lot of scripts to handle this, but it's possible. There's
some examples at: www.javascripter.net/faq/sound/stop.htm on how to shut it
off in IE and Navigator, but you'll have to get the code to find out which
browser it is seperately and plop these samples in there. I haven't tested
them myself though so I can't say if they work correctly or not.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 
T

Trevor L.

Mark,

At the moment I use a cookie to control playing music on entry. If the
cookie is not set, the music plays.
Otherwise,otherwise. So I thought I'd try the suggestion in the link you
gave.

This is my code:
<embed src="minuet.mid" id="theNoise" name="theNoise"
width="144" height="45" autostart="true" loop="false">
<input type="button" value="Stop
Sound"
onClick="document.all['theNoise'].src='jsilence.mid'">
where jsilence.mid is just an empty file

The msuic plays fine, but pressing the "Stop Sound" button does nothing.

I am using IE6.

Any ideas anyone?
 
T

Terry Stockdale

I never cease to wonder why people think automatic background sound on
a website is a "good thing."

Instead of generating a sound and allowing the user to turn it off
(or, as I do, leave the website!), why don't you create a quiet
website and let the user click on a button to play the music.
 
T

Trevor L.

Terry,
Your point is quite valid, whcih is why I have been trying to acheive just
this option - either to play or not to play the music.

It took me a lot of trial and error before I got it right. (See other
threads on the topic.)

This is the code I came up with, which works in both IE6 and Firefox - and
hopefully other browsers as well
function playSound()
{ document.getElementById("sound").innerHTML= '<embed src="minuet.wav"
loop=false autostart=true hidden>' }
function stopSound()
{ document.getElementById("sound").innerHTML= ''}

<span id="sound"></span>
<input type="button" value="Play
Music" onClick="playSound()">
<input type="button" value="Stop
Music" onClick="stopSound()">

All other attempts failed in Firefox. This one worked.

So, for anyone wanting to add music, please feel freee to copy this so as to
give the visitor the choice.
--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au

Terry said:
I never cease to wonder why people think automatic background sound on
a website is a "good thing."

Instead of generating a sound and allowing the user to turn it off
(or, as I do, leave the website!), why don't you create a quiet
website and let the user click on a button to play the music.

--
Terry
My blog: http://www.TheNextWindow.com
My home theater site: http://www.TerrysHomeTheater.com
My tip site and newsletter: http://www.TerrysComputerTips.com


Mark,

At the moment I use a cookie to control playing music on entry. If
the cookie is not set, the music plays.
Otherwise,otherwise. So I thought I'd try the suggestion in the link
you gave.

This is my code:
<embed src="minuet.mid" id="theNoise" name="theNoise"
width="144" height="45" autostart="true" loop="false">
<input type="button" value="Stop
Sound"
onClick="document.all['theNoise'].src='jsilence.mid'">
where jsilence.mid is just an empty file

The msuic plays fine, but pressing the "Stop Sound" button does
nothing.

I am using IE6.

Any ideas anyone?
 

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

Top