0

So I've got some buttons, which people can press to hear audio files. Of course, the audio files can't "overlap" because that would be a mess. This works, but now I want one of the files to play automatically when the website loads, still maintaining the fact that it will stop whenever I press another button.

This is what I've got so far:

Head:

<script language="javascript" type="text/javascript">
 function playSound(soundfile) {
 document.getElementById("dummy").innerHTML=
 "<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"false\" loop=\"true\" />";
 }
 </script>

Body:

<span id="dummy"></span>

<p style="text-align:center;">
<a href="#" onclick="playSound('Sound1.mp3');"> 
<img class="alignnone" width="128" img src="Img1.png" ></a>

<a href="#" onclick="playSound('Sound2.mp3');"> 
<img class="alignnone" width="128" img src="Img2.png"  ></a>

<a href="#" onclick="playSound('Sound3.mp3');"> 
<img class="alignnone" width="128" img src="Img3.png"  ></a>
</p>
user229044
  • 232,980
  • 40
  • 330
  • 338

1 Answers1

0

Try this jquery solution:

http://archive.plugins.jquery.com/project/sound_plugin

I used this successfully in a reaction time test where I had to play a sound just before each test.

karmafunk
  • 1,453
  • 12
  • 20