Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Sound on/off button does not work

Reply
Thread Tools

Sound on/off button does not work

 
 
Fokke Nauta
Guest
Posts: n/a
 
      12-07-2011
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>


 
Reply With Quote
 
 
 
 
Denis McMahon
Guest
Posts: n/a
 
      12-07-2011
On Wed, 07 Dec 2011 12:46:13 +0100, Fokke Nauta wrote:

> 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/chec...pc3.nl%2Ftest%
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
 
Reply With Quote
 
 
 
 
Fokke Nauta
Guest
Posts: n/a
 
      12-07-2011
"Denis McMahon" <(E-Mail Removed)> wrote in message
news:4edf9765$0$29307$(E-Mail Removed) .com...
> On Wed, 07 Dec 2011 12:46:13 +0100, Fokke Nauta wrote:
>
>> 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/chec...pc3.nl%2Ftest%
> 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


 
Reply With Quote
 
Jukka K. Korpela
Guest
Posts: n/a
 
      12-07-2011
2011-12-07 20:48, Fokke Nauta wrote:

> 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.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
 
Reply With Quote
 
David Mark
Guest
Posts: n/a
 
      12-07-2011
On Dec 7, 11:42*am, Denis McMahon <(E-Mail Removed)> wrote:
> On Wed, 07 Dec 2011 12:46:13 +0100, Fokke Nauta wrote:
> > 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/chec...pc3.nl%2Ftest%
> 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.
>


(a) Did you really need the validator to tell you that?
(b) It's not supported in any doctype.
 
Reply With Quote
 
David Mark
Guest
Posts: n/a
 
      12-08-2011
On Dec 7, 5:09*pm, "Jukka K. Korpela" <(E-Mail Removed)> wrote:
> 2011-12-07 20:48, Fokke Nauta wrote:
>
> > 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.


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.
 
Reply With Quote
 
Fokke Nauta
Guest
Posts: n/a
 
      12-08-2011
"David Mark" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
On Dec 7, 5:09 pm, "Jukka K. Korpela" <(E-Mail Removed)> wrote:
> 2011-12-07 20:48, Fokke Nauta wrote:
>
> > 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.


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


 
Reply With Quote
 
Denis McMahon
Guest
Posts: n/a
 
      12-09-2011
On Thu, 08 Dec 2011 20:23:51 +0100, Fokke Nauta wrote:

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


http://www.lmgtfy.com/?q=html5+embed+audio

Rgds

Denis McMahon
 
Reply With Quote
 
David Mark
Guest
Posts: n/a
 
      12-09-2011
On Dec 8, 7:10*pm, Denis McMahon <(E-Mail Removed)> wrote:
> On Thu, 08 Dec 2011 20:23:51 +0100, Fokke Nauta wrote:
> > OK, HTML5 then. With a fall back to the old BGSOUND element. If you
> > could give me an example ...

>
> http://www.lmgtfy.com/?q=html5+embed+audio
>


What a completely worthless response. Trying to appear clever? It
requires actual cleverness.

You already know where to find the BGSOUND fallback (if you read the
thread before posting). And why would you include "embed" in the query
(again, assuming you actually read the previous posts?)
 
Reply With Quote
 
Denis McMahon
Guest
Posts: n/a
 
      12-09-2011
On Wed, 07 Dec 2011 12:46:13 +0100, Fokke Nauta wrote:

> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Having trouble getting new sound card to work - had onboard sound Dora Smith Computer Information 1 11-23-2006 04:31 PM
Power button does not turn OFF? New power supply does not help! win2k lbbss Computer Support 0 01-06-2005 04:03 PM
Laptop sound channel does not work -any suggestions? Gary Glencross Computer Information 1 09-25-2004 08:07 PM
Webservice works once and then DOES NOT seem to work even though program does not crash Phi! ASP .Net Web Services 1 04-23-2004 08:42 AM
Onboard sound card does not work Rainer Schmandt Computer Support 13 11-02-2003 03:43 PM



Advertisments