Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / June 2005



Tip: Looking for answers? Try searching our database.

Playing an audio file using Javascript

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
laredotornado@zipmail.com - 29 Jun 2005 14:12 GMT
Hello, I had been given this code to play a single sound file embedded
in a page.  Sadly, the code doesn't actually "play" any sound file.
Could you help supply some JS code that will play a sound file for both
IE and Mozilla?

Thanks, - Dave

<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 - 29 Jun 2005 15:07 GMT
> Hello, I had been given this code to play a single sound file embedded
> in a page.

Yes, that was me given you that code.
Have you included your sound file into the call here:

>      onmouseover="Sound.play('klatschn.wav')"

Daniel
laredotornado@zipmail.com - 30 Jun 2005 15:52 GMT
Oops, I forgot that line.

Everything works great on all platforms, browsers.  Thanks! -
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.