Different Ways to Play a Sound from a Web Page8. Using a Java Applet called from JavaScriptThe Java applet in section 7 can be stripped down so that it just loads the audio file and then replays it under command from a JavaScript function. Effectively this is using a Java applet instead of an embedded media player object. However you will need the Java plug-in to run this (see section 7). You can replace the image by a 1x1 pixel transparent gif, if you don't want a picture. <applet code="AudioPlay.class" id="Audio1" width="40" height="40"> <param name="image" value="play.gif"> <param name="audio" value="success.wav"> </applet>
<script>
function EvalSound(soundobj) {
var thissound=document.getElementById(soundobj);
thissound.Play();
}
</script>
<form>
<input type="button" value="Play Sound" onClick="EvalSound('Audio1')">
</form>
You'll also need to download the AudioPlay.class file.
| ||