Sound on/off button does not work

Discussion in 'Javascript' started by Fokke Nauta, Dec 7, 2011.

  1. Fokke Nauta

    Fokke Nauta Guest

    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>
     
    Fokke Nauta, Dec 7, 2011
    #1
    1. Advertising

  2. 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/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
     
    Denis McMahon, Dec 7, 2011
    #2
    1. Advertising

  3. Fokke Nauta

    Fokke Nauta Guest

    "Denis McMahon" <> wrote in message
    news:4edf9765$0$29307$...
    > 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/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
     
    Fokke Nauta, Dec 7, 2011
    #3
  4. 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/
     
    Jukka K. Korpela, Dec 7, 2011
    #4
  5. Fokke Nauta

    David Mark Guest

    On Dec 7, 11:42 am, Denis McMahon <> 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/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.
    >


    (a) Did you really need the validator to tell you that? :)
    (b) It's not supported in any doctype.
     
    David Mark, Dec 7, 2011
    #5
  6. Fokke Nauta

    David Mark Guest

    On Dec 7, 5:09 pm, "Jukka K. Korpela" <> 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. ;)
     
    David Mark, Dec 8, 2011
    #6
  7. Fokke Nauta

    Fokke Nauta Guest

    "David Mark" <> wrote in message
    news:...
    On Dec 7, 5:09 pm, "Jukka K. Korpela" <> 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
     
    Fokke Nauta, Dec 8, 2011
    #7
  8. 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
     
    Denis McMahon, Dec 9, 2011
    #8
  9. Fokke Nauta

    David Mark Guest

    On Dec 8, 7:10 pm, Denis McMahon <> 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?)
     
    David Mark, Dec 9, 2011
    #9
  10. 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
     
    Denis McMahon, Dec 9, 2011
    #10
  11. Fokke Nauta

    David Mark Guest

    On Dec 8, 2:23 pm, "Fokke Nauta" <> wrote:
    > "David Mark" <> wrote in message
    >
    > news:...
    > On Dec 7, 5:09 pm, "Jukka K. Korpela" <> 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 ...
    >


    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.
     
    David Mark, Dec 9, 2011
    #11
  12. Fokke Nauta

    Fokke Nauta Guest

    "Denis McMahon" <> wrote in message
    news:4ee15945$0$29435$...
    > 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.


    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
     
    Fokke Nauta, Dec 10, 2011
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Han
    Replies:
    1
    Views:
    574
    Oliver
    Nov 12, 2003
  2. Julia
    Replies:
    4
    Views:
    10,326
    Dan Linn
    Jun 29, 2005
  3. Luc The Perverse

    Sound Quality In Sound API

    Luc The Perverse, Oct 30, 2005, in forum: Java
    Replies:
    4
    Views:
    1,490
    Andrew Thompson
    Oct 31, 2005
  4. Replies:
    0
    Views:
    507
  5. Andy Fish

    customErrors mode="Off" does not work

    Andy Fish, Mar 31, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    655
    Alvin Bruney [ASP.NET MVP]
    Apr 2, 2008
Loading...

Share This Page