954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Play Sound with javascript DHTML

How to play sound file like .wav file with javascript and/or DHTML when some one mouseover to a link. I have done this... but it only works in IE while it does not work in other browsers like firefox and chrome.

Can any body help me regarding this issue.

arshadshaikh
Newbie Poster
18 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

This should work!
If not then try to check you plug-ins...

<html>
<head>
<title><!-- Sample --></title>
<script type="text/javascript">
<!--
function playSound( mysound )
{ thisSound = document.getElementById(mysound);
  thisSound.Play();
}
//-->
</script>
</head>
<body>
<embed src="someaudiofile.mp3/mid/wav" autostart="false" width="0" height="0" id="sound1" enablejavascript="true" />

<a href="javascript:void(0);" onmouseover="playSound('sound1');">Play Sound!</a>
</body>
</html>
essential
Posting Shark
974 posts since Aug 2008
Reputation Points: 114
Solved Threads: 138
 

Thank you so much for your kind help. Its working in firefox. But actually problem is this that with this script sound does not come instantly as it comes in other script which i use for IE.

arshadshaikh
Newbie Poster
18 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 
p_midtlyng
Newbie Poster
3 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

Following is the code that the author at this website claims that it runs on every browser. (99%)

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
    width="40"
    height="40"
    id="audio1"
    align="middle">
    <embed src="wavplayer.swf?h=1&w=1"
        bgcolor="#ffffff"
        width="40"
        height="40"
        allowScriptAccess="always"
        type="application/x-shockwave-flash"
        pluginspage="http://www.macromedia.com/go/getflashplayer"
    />
</object>
 
<script>
function getPlayer(pid) {
    var obj = document.getElementById(pid);
    if (obj.doPlay) return obj;
    for(i=0; i<obj.childNodes.length; i++) {
        var child = obj.childNodes[i];
        if (child.tagName == "EMBED") return child;
    }
}
function doPlay(fname) {
    var player=getPlayer("audio1");
    player.play(fname);
}
function doStop() {
    var player=getPlayer("audio1");
    player.doStop();
}
</script>
 
<form>
<input type="button" value="Play Sound" onClick="doPlay('duck.wav')">
<input type="button" value="Stop Sound" onClick="doStop()">
</form>
falakniazi
Newbie Poster
5 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You