Hi Paul,
better late then never! ;-)
I found a website that could interest you:
http://www.boutell.com/newfaq/creating/scriptsound.html
I made some changes that can work for you:
----------------------- Start of HTML -----------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Play sound from JavaScript</title>
<script>
<!--
// reference: http://www.boutell.com/newfaq/creating/scriptsound.html
var currentsound;
function playSound(soundname) {
var nextsound = eval("document." + soundname);
// make an effort to stop and rewind any playback
// already in progress so that the sound starts over.
// Otherwise this call has no effect when the sound
// is already in progress. You can remove these lines
// if you don't like this behavior.
try {
if(currentsound != null) {
currentsound.Stop();
currentsound.Rewind();
}
} catch (e) {
// A player that doesn't support
// Stop and Rewind
}
currentsound = nextsound;
try {
// For RealPlayer-enabled browsers.
// Some versions of RealPlayer do not
// offer a Play() function and will
// fail to play sound if we try to
// call Play().
currentsound.DoPlay();
} catch (e) {
// If DoPlay doesn't work, call Play.
// This works for all other audio
// plug-ins.
currentsound.Play();
}
}
-->
</script>
</head>
<body>
<embed src="soundone.wav" width="-1" height="-1" autostart="false"
name="soundone" enablejavascript="true">
<embed src="soundtwo.wav" width="-1" height="-1" autostart="false"
name="soundtwo" enablejavascript="true">
<!-- aso. -->
<a href="#" onMouseOver="playSound('soundone');">sound one</a>
<a href="#" onMouseOver="playSound('soundtwo');">sounde two</a>
<!-- aso. -->
</body>
</html>
----------------------- End of HTML -----------------------
Interesting to look at is:
1) You need try catches for browsers that doesn't support a plug-in
for DoPlay/Play/Stop/Rewind. I guess RealPlayer is using DoPlay!?
2) The "currentsound" is a "global" variable.
3) You need rewind, or the sound will start where it stopped last time!
4) Ohh yeah the sounds are loaded at page-load! So you can address
them all the time.
5) The soundname in fx. "playSound('soundone')" is the one from the
embed-tag with the name-attribute set to "soundone".
Kindest regards,
Kim
--
The way is the destination.
Hi Paul,
better late then never! ;-)
I found a website that could interest you:
http://www.boutell.com/newfaq/creating/scriptsound.html
I made some changes that could work for you:
var currentsound;
currentsound = nextsound;
<body>
<embed src="kpp.wav" width="0" height="0" autostart="false"
name="sound1" enablejavascript="true">
<embed src="xpblkpop.wav" width="0" height="0" autostart="false"
name="sound2" enablejavascript="true">
<embed src="xpfeeddisc.wav" width="0" height="0" autostart="false"
name="sound3" enablejavascript="true">
<embed src="xpinfbar.wav" width="0" height="0" autostart="false"
name="sound4" enablejavascript="true">
<!-- aso. -->
<a href="#" onMouseOver="playSound('sound1');">sound1</a>
<a href="#" onMouseOver="playSound('sound2');">sound2</a>
<a href="#" onMouseOver="playSound('sound3');">sound3</a>
<a href="#" onMouseOver="playSound('sound4');">sound4</a>
<!-- aso. -->
</body>
</html>
----------------------- End of HTML -----------------------
Interesting to look at is:
1) You need try catches for browsers that doesn't support a plug-in
for DoPlay/Play/Stop/Rewind. I guess RealPlayer is using DoPlay!?
2) The "currentsound" is a "global" variable.
3) You need rewind, or the sound will start where it stopped last time!
4) Ohh yeah the sounds are loaded at page-load! So you can address
them all the time.
5) The soundname in fx. "playSound('soundone')" is the one from the
embed-tag with the name-attribute set to "soundone".
6) Do NOT use the "hidden" attribute inside the embed-tag!
There is a little disfigurement in Internet Explorer, when you are using
width="0" height="0" instead of the hidden-attribute (small dots where
the embed-tags are placed)!
It doesn't need to be a *.wav file, it could be any audio/video file,
just try it out.