Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   Playing an audio file using Javascript (http://www.velocityreviews.com/forums/t918919-playing-an-audio-file-using-javascript.html)

laredotornado@zipmail.com 06-29-2005 01:12 PM

Playing an audio file using Javascript
 
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 06-29-2005 02:07 PM

Re: Playing an audio file using Javascript
 
laredotornado@zipmail.com wrote:
> 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 06-30-2005 02:52 PM

Re: Playing an audio file using Javascript
 
Oops, I forgot that line.

Everything works great on all platforms, browsers. Thanks! -



All times are GMT. The time now is 11:10 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.