Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Input button used for object sound off "sort a working"

    Hi, First time here!
    I started off with an "embed" audio clip with auto play and hidden at the site and later released some people want the option to turn off the music. When looking for a way to add a stop button I found out "embed" and for that matter "bgsound" are long ago "depreciated" by W3C and will not validate. I found a novel way to implement the object tag that doesn't require classid for a particular player and it WORKS. http://alistapart.com/articles/byebyeembed Now for the button part, I found a js function to turn on/off sound at: http://aaiddennium.online.lt/blog/20...l-sounds-well/ but the example uses mouseover/out. I thought using an input button (stop only) would go good and for the most part it works. Sometimes the button will disappear when clicked or if you click randomly on the page it will glitch the page. Validator shows two uses for id "sound" and I know thats no good but I don't know exactly how to replace one and still have that function, Im sure this is the problem. Note, I can drop the input button if need be and add another Li link but not sure how to do that either. I thank you experts for listening and any help. Site: http://daisysdiner.com/love

    [ <object type="audio/x-ms-wma" id="sound" data="images/love.wma" width="0" height="0">
    <param name="src" value="images/love.wma" />
    <param name="autostart" value="true" />
    <param name="controller" value="false" />
    </object>
    <div id="soundbutton"><input type="button" id="sound" value="Stop Music" onclick="stopSound()" /></div> ]

    Note: div id is used only for positioning the button in css.


    [ function stopSound() {
    var oSound = document.getElementById('sound');
    if (oSound && oSound.object) {
    oSound.stop();
    } else {
    oSound.parentNode.removeChild(oSound);
    }
    }

    function playSound() {
    var oSound = document.getElementById('sound');
    if(oSound && oSound.object) {
    oSound.play();
    } else {
    if (oSound) {
    oSound.parentNode.removeChild(oSound);
    }
    var SOUND_FILE = 'images/love.wma';
    oSound = document.createElement('object');
    oSound.setAttribute('id', 'sound');
    oSound.setAttribute('width', '0');
    oSound.setAttribute('height', '0');
    oSound.setAttribute('data', SOUND_FILE);
    oSound.setAttribute('type', 'audio/x-ms-wma');
    var oParam = document.createElement('param');
    oParam.setAttribute('name', 'src');
    oParam.setAttribute('value', SOUND_FILE);
    oSound.appendChild(oParam);

    oParam = document.createElement('param');
    oParam.setAttribute('name', 'ShowAudioControls');
    oParam.setAttribute('value', 'false');
    oSound.appendChild(oParam);

    oParam = document.createElement('param');
    oParam.setAttribute('name', 'ShowControls');
    oParam.setAttribute('value', 'false');
    oSound.appendChild(oParam);

    oParam = document.createElement('param');
    oParam.setAttribute('name', 'AutoStart');
    oParam.setAttribute('value', 'true');
    oSound.appendChild(oParam);

    oParam = document.createElement('param');
    oParam.setAttribute('name', 'loop');
    oParam.setAttribute('value', 'true');
    oSound.appendChild(oParam);
    document.body.appendChild(oSound);
    }
    } ]

  • #2
    Regular Coder
    Join Date
    Sep 2005
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm thinking this is the problem too... The removeChild(oSound) would be the cause of the button disappearing, etc. Since it is the <object> and not the button that is being addressed in these functions, just change the id of the button to something like "soundbtn".
    If you want answers, write a smart question.

    Yes, someone probably does know how...

    Oh, and if you want to learn, STFW!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •