473,327 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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>

Jul 23 '05 #1
2 7911
la***********@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
Jul 23 '05 #2
Oops, I forgot that line.

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

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Peter Schmitz | last post by:
Hi, I'm just trying to play a *.wav file, making use of the unmanaged function "sndPlaySoundA" in winmm.dll, but I still got one question: How can I avoid, that the sound file itself has to be...
1
by: laredotornado | last post by:
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...
2
by: Greg Smith | last post by:
Hi, is there a simple way to play a short audio file? Some of my users would like to hear "There is a new order for your approval" when ever the situation calls for it. Is this do-able? Any...
7
by: Lee Moody | last post by:
I just want quick and easy way to play a .wav file out the standard sound device. It could even be as simple as activating a sound assigned to an existing windows sound event. Any suggestions?...
3
by: abrtlt | last post by:
I would like to have a web page in which, when the user clicks on any of several specific elements, a specific audio file is played, without reloading the page. The specific audio file name is...
4
by: fAnSKyer/C# newbie | last post by:
I am using winmm.dll and I found that I can't just suspend it and resume it? What should I do? Any better idea? Should I use thread? and thread.suspend will work? Thanks
0
by: Sobin Thomas | last post by:
Hi,All... I found in one of the articles on the net that an audio file can be played in asp.net by setting the Hyperlink's Navigate Url as the audio file name. ie,...
0
by: Sobin Thomas | last post by:
Hi,All... I found in one of the articles on the net that an audio file can be played in asp.net by setting the Hyperlink's Navigate Url as the audio file name. ie,...
1
by: Sobin Thomas | last post by:
Hi,All... I found in one of the articles on the net that an audio file can be played in asp.net by setting the Hyperlink's Navigate Url as the audio file name. ie,...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.