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.

Recommended Answers

All 4 Replies

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" />
<br />
<a href="javascript:void(0);" onmouseover="playSound('sound1');">Play Sound!</a>
</body>
</html>

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.

Hello -
I'm new to dynamic webpages, and I need some help.
This thread is relevant to me, but does not exactly answer my question.

The code below generates a webpage that automatically plays a part of a soundfile, depending on what name and start and end times are delivered to it in the PHP part of the code.

The question I have is that in Opera, Firefox/Mozilla everything works perfectly, and you can click on the .gif and the script will run again and the sound will play again. However this is not the case in IE. The script will run, and play part of the section that it is supposed to play, but not all of it, and if it does not play all of it, clicking on the .gif generates a 'null' is null or not an object error. Line 16 Char 1.

Any help would be much appreciated.

P.

<?php

$filename=$_GET['filename'];
$starttime=$_GET['starttime'];
$endtime=$_GET['endtime'];

print '
<html>

<head>
<meta name=Title content="Digital Maya Website Audio">
<meta name=Keywords content="">
<meta http-equiv=Content-Type content="text/html; charset=macintosh">

<LINK REL=StyleSheet HREF="style.css" TYPE="text/css" MEDIA=screen>

<title>Website Title</title>

<script>
function EvalSound(soundobj) {
  var thissound=document.getElementById(soundobj);
  thissound.Play();
}
</script>

</head>

<body bgcolor=white lang=EN-US style="border:0;margin=0;align=center">

<div class=Section1>

<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width=0
height=0>
<param name="src" value="'.$filename.'">
<param name="scale" value="tofit">
            <param name="controller" value="true">
            <param name="autoplay" value="true">
            <param name="loop" value="false">
            <param name="starttime" value="'.$starttime.'">
            <param name="endtime" value="'.$endtime.'">
            <embed src="'.$filename.'" id="s001" scale=tofit width=1 height=1 align=center controller=false autoplay=true 
loop=false starttime="'.$starttime.'" endtime="'.$endtime.'" enablejavascript=true 
pluginspage="http://www.apple.com/quicktime/download/" type="video/quicktime"></EMBED></OBJECT>

<form>
<img src="http://www.webucateus.com/dotnetnuke/Portals/0/Cache/images/soundIcon.gif" height=50 onClick="EvalSound(\'s001\')">
</form>

</div>

</body>
</html>
';
?>

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>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.