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

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

  3. Fokke Nauta

    Fokke Nauta Guest

    Hi Dennis,

    I just did and was surpised with the amount of errors.
    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. 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.
     
    Jukka K. Korpela, Dec 7, 2011
    #4
  5. Fokke Nauta

    David Mark Guest

    (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

    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.
    Pays off for control-freak designers, but stiffs the users. ;)
     
    David Mark, Dec 8, 2011
    #6
  7. Fokke Nauta

    Fokke Nauta Guest

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

    Fokke
     
    Fokke Nauta, Dec 8, 2011
    #7
  8. Denis McMahon, Dec 9, 2011
    #8
  9. Fokke Nauta

    David Mark Guest

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

    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

    I fully agree.
    Fully agree as well.
    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. Advertisements

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 (here). After that, you can post your question and our members will help you out.