Playing an audio file without spawning a new window ...

Discussion in 'Javascript' started by laredotornado@zipmail.com, Jun 15, 2005.

  1. Guest

    Hello, I want to play an audio file embedded on my page by clicking on
    an audio image and the page change to a new page. Is there a
    cross-browser Javascript way to do this? Right now the code I have
    is ...

    <html>
    <head>
    <title>Dictionary: homeostasis</title>
    <link href="liveink.css" type="text/css" rel="stylesheet"/>
    </head>
    <body>
    <div class="dictionary-area">
    <span class="dictionary-word">homeostasis</span>
    (<span class="dictionary-pos">Noun</span>)
    <br/>
    <div class="dictionary-defn">The maintenance of a constant internal
    state in a changing environment that is maintained by continually
    making adjustments to the internal and external environment.</div>
    <a href="homeostasis.mp3" target="new"><img src="audio.gif"
    border="0"></a>
    <div class="dictionary-close-window"><a
    href="javascript:window.close()">Close Window</a></div>
    </div>
    </body>
    </html>

    The inconvenience is right now a new window is spawned to play the
    audio., which contains the controller for playing the audio (complete
    with pause, stop, and play buttons). All my audio clips are less than
    3 seconds in length.. How can I play the audio file without launching
    the controller? I don't care if there's no way to stop/pause the audio
    once it's started.

    Thanks for your help, - Dave
    , Jun 15, 2005
    #1
    1. Advertising

  2. wrote:
    > How can I play the audio file without launching
    > the controller? I don't care if there's no way to stop/pause the audio
    > once it's started.


    Try this:

    <html>
    <head>
    <title>Make some noize</title>

    <script type="text/javascript">
    <!--

    var Sound = new Object();
    Sound.play = function Sound_play(src) {
    if (!src) return false;
    this.stop();
    var elm;
    if (typeof document.all != "undefined") {
    elm = document.createElement("bgsound");
    elm.src = src;
    }
    else {
    elm = document.createElement("object");
    elm.setAttribute("data",src);
    elm.setAttribute("type","audio/x-wav");
    elm.setAttribute("controller","true");
    }
    document.body.appendChild(elm);
    this.elm = elm;
    return true;
    };

    Sound.stop = function Sound_stop() {
    if (this.elm) {
    this.elm.parentNode.removeChild(this.elm);
    this.elm = null;
    }
    };

    //-->
    </script>
    </head>

    <body>
    <div
    onmouseover="Sound.play('klatschn.wav')"
    onmouseout="Sound.stop()">Come over me</div>
    </body>
    </html>
    Daniel Kirsch, Jun 15, 2005
    #2
    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. POL8985
    Replies:
    1
    Views:
    542
    Kevin Spencer
    Jan 31, 2005
  2. aeonsun
    Replies:
    2
    Views:
    418
    Luc The Perverse
    Mar 11, 2007
  3. Sobin Thomas

    Doubt-Playing audio file in asp.net

    Sobin Thomas, May 21, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    372
    Sobin Thomas
    May 21, 2008
  4. Sobin Thomas

    Playing audio file in asp.net???

    Sobin Thomas, May 22, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    1,339
    George Ter-Saakov
    May 22, 2008
  5. Sobin Thomas

    Playing an audio file in our site???

    Sobin Thomas, May 23, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    315
Loading...

Share This Page