Sound on/off button does not work

F

Fokke Nauta

Hi all,

I searched for a sound on/off button for web pages. The script I found I
placed in an HTML document. I adapted it only to suit a different sound file
and to change the text on the button.
It does not work though. The original version didn't work either.
The button changes allright but the sound stays on.
Can any one help me out?

The script is underneath this post. The web page is on www.pc3.nl/test and
is called test.htm.

Many thanks in advance for your help.

With best regards,
Fokke Nauta

Script:

In header:
----------
<script language="JavaScript">
<!--
function musicOff() {
document.midi.stop()
}
function musicOn() {
document.midi.play()
}
function changeButton() {
if (document.onoff.B1.value=='Sound off') {
document.onoff.B1.value='Sound on';
musicOff()
}
else {
document.onoff.B1.value='Sound off';
musicOn()
}
}
//-->
</script>

In body:
--------
<embed name="midi" src="Lauquette.mp3" loop="true" width=0 height=0
hidden="true">
<form name="onoff">
<input type="button" value="Sound off" name="B1" onClick="changeButton()">
</form>
 
D

Denis McMahon

I searched for a sound on/off button for web pages. The script I found I
placed in an HTML document. I adapted it only to suit a different sound
file and to change the text on the button. It does not work though. The
original version didn't work either. The button changes allright but the
sound stays on. Can any one help me out?

Have you tried the following:

http://validator.w3.org/unicorn/check?ucn_uri=www.pc3.nl/test%
2Ftest.htm&ucn_task=conformance#

which suggests to me that (a) your script element is incorrectly defined
and (b) the embed element isn't supported in the defined doctype.

Rgds

Denis McMahon
 
F

Fokke Nauta

Denis McMahon said:
Have you tried the following:

http://validator.w3.org/unicorn/check?ucn_uri=www.pc3.nl/test%
2Ftest.htm&ucn_task=conformance#

Hi Dennis,

I just did and was surpised with the amount of errors.
which suggests to me that (a) your script element is incorrectly defined
and (b) the embed element isn't supported in the defined doctype.

Well, I used the embed element on other webpages with the same doctype and
it works perfectly.
But which doctype should I choose, to start with?

Regards,
Fokke
 
J

Jukka K. Korpela

Well, I used the embed element on other webpages with the same doctype and
it works perfectly.

Forget the doctype and validation issues for the moment. They do not
affect the problem at hand.

The question is: can you expect the <embed> element to have play() and
stop() methods?

You might consider using the HTML5 <audio> element, with its play() and
pause() methods, but then you would need to deal with the varying
support to this element (well, you could use <embed> as fallback
content) and varying support to different audio media types with it.

Does it really pay off, as opposite to using <embed> with its own
visible controls? I'd expect most users to prefer those controls (which
they have encountered on other pages) to your site- or page-specific
special controls.
 
D

David Mark

Forget the doctype and validation issues for the moment. They do not
affect the problem at hand.
Right.


The question is: can you expect the <embed> element to have play() and
stop() methods?
Nope.


You might consider using the HTML5 <audio> element, with its play() and
pause() methods, but then you would need to deal with the varying
support to this element (well, you could use <embed> as fallback
content) and varying support to different audio media types with it.

Could use the My Library audio module (or the like if can find one) as
the fallback. The book on EMBED/OBJECT-based audio was written ten
years ago. Quick review: it stinks; plug-ins are unreliable. And if
you need to support IE, you should use BGSOUND elements, which is also
taken care of by this module.

You might also consider using an HTML5-based solution and then falling
straight back to the BGSOUND shenanigans. Could even put the latter
in conditional comments. After all, who cares if audio features are
available in old versions of Firefox, Safari, Opera, etc.? Best to
leave the EMBED/OBJECT crap out of it at this point.
Does it really pay off, as opposite to using <embed> with its own
visible controls? I'd expect most users to prefer those controls (which
they have encountered on other pages) to your site- or page-specific
special controls.

Pays off for control-freak designers, but stiffs the users. ;)
 
F

Fokke Nauta

Forget the doctype and validation issues for the moment. They do not
affect the problem at hand.

Right.

OK, this makes sense.
The question is: can you expect the <embed> element to have play() and
stop() methods?

Nope.

And this makes sense as well. So, the script I found was crap.
You might consider using the HTML5 <audio> element, with its play() and
pause() methods, but then you would need to deal with the varying
support to this element (well, you could use <embed> as fallback
content) and varying support to different audio media types with it.

Could use the My Library audio module (or the like if can find one) as
the fallback. The book on EMBED/OBJECT-based audio was written ten
years ago. Quick review: it stinks; plug-ins are unreliable. And if
you need to support IE, you should use BGSOUND elements, which is also
taken care of by this module.

You might also consider using an HTML5-based solution and then falling
straight back to the BGSOUND shenanigans. Could even put the latter
in conditional comments. After all, who cares if audio features are
available in old versions of Firefox, Safari, Opera, etc.? Best to
leave the EMBED/OBJECT crap out of it at this point.

OK.
Can you give me an example of how to code this?
Does it really pay off, as opposite to using <embed> with its own
visible controls? I'd expect most users to prefer those controls (which
they have encountered on other pages) to your site- or page-specific
special controls.

Pays off for control-freak designers, but stiffs the users. ;)

OK, HTML5 then. With a fall back to the old BGSOUND element.
If you could give me an example ...

Fokke
 
D

Denis McMahon

I searched for a sound on/off button for web pages.

I tend to provide links to any multi media files that are related to web
pages that I write, rather than try and force users to view / listen to
them.

It goes along with my gross distaste for websites written in flash /
silverlight / etc.

OK they can look very glossy, but they start getting painfully slow on
some machines and hogging resources, and I often end up navigating away
from the website and looking elsewhere.

So, is the audio file actually essential to the enable the user to
understand the website content, or is it an aesthetic add-on that could
be safely dumped?

Rgds

Denis McMahon
 
D

David Mark

Right.

OK, this makes sense.




Nope.

And this makes sense as well. So, the script I found was crap.




Could use the My Library audio module (or the like if can find one) as
the fallback.  The book on EMBED/OBJECT-based audio was written ten
years ago.  Quick review: it stinks; plug-ins are unreliable.  And if
you need to support IE, you should use BGSOUND elements, which is also
taken care of by this module.

You might also consider using an HTML5-based solution and then falling
straight back to the BGSOUND shenanigans.  Could even put the latter
in conditional comments.  After all, who cares if audio features are
available in old versions of Firefox, Safari, Opera, etc.?  Best to
leave the EMBED/OBJECT crap out of it at this point.

OK.
Can you give me an example of how to code this?




Pays off for control-freak designers, but stiffs the users.  ;)

OK, HTML5 then. With a fall back to the old BGSOUND element.
If you could give me an example ...

Of what? How to use the HTML5 AUDIO element? Or how to detect
whether your chosen audio format(s) are likely to work? If the
detection fails, you have to replace the AUDIO element with an
alternative (or simply remove it in the case of a BGSOUND-based
fallback script).

And appending/removing a BGSOUND element is trivial. They go in the
HEAD. No format detection needed. WAV for effects or MP3 for music.
 
F

Fokke Nauta

Denis McMahon said:
I tend to provide links to any multi media files that are related to web
pages that I write, rather than try and force users to view / listen to
them.

I fully agree.
It goes along with my gross distaste for websites written in flash /
silverlight / etc.

OK they can look very glossy, but they start getting painfully slow on
some machines and hogging resources, and I often end up navigating away
from the website and looking elsewhere.

Fully agree as well.
So, is the audio file actually essential to the enable the user to
understand the website content, or is it an aesthetic add-on that could
be safely dumped?

Well, if it was up to me, I would dump it straight away. And whether the
add-on is aesthetic or not is discussable.
But the owner of a website wanted this sound as a background sound on
multiple pages. Happily he came up with the idea that visitors would have
been able to turn of this sound.

Regards,
Fokke
 

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,731
Latest member
MarcyGipso

Latest Threads

Top