To embed a sound clip into a Web page, use the <embed> tag. The syntax of this tag is:
where URL is the filename and location of the embedded object, and the width and height attributes define the size of the embedded object on the Web page (you need to set the size large enough to display the necessary controls for the user to play the media clip).
The autostart attribute is used to define whether or not the browser starts the embedded clip automatically when the Web page is loaded. This attribute can take on values true or false.
Example:
| <embed src="surprise.wav" width="150" height="60" autostart="false" /> |
Try how it works:
Internet Explorer introduced this tag for playing background sounds on your Web page. The syntax of the <bgsound> tag is:
where the balance attribute defines how the sound should be balanced between the computer's left and right speakers (the value for balance varies between -10000 and 10000), the volume attribute indicates the volume of the sound (its value varies between 0 and 10000), and the loop attribute specifies how many times the clip is played. The value of the loop attribute can either be an integer number 1 (default), 2, 3 ... or "infinite" if you want the sound to be played continuously.
Background sound for this Web page is embedded by using the following code:
| <bgsound src="hazy_shade_of_winter.mid" balance="0" volume="2000" loop="2" /> |
Netscape does not support <bgsound> tag. However, you can use the <embed> tag by setting the width/height values to 0. The following JavaScript code checks which browser do you use and writes the corresponding code to the Web page.
| JavaScript code |
|---|
<script language="JavaScript">
var filename="hazy_shade_of_winter.mid";
if (navigator.appName == "Microsoft Internet Explorer")
document.writeln ('<bgsound src="' + filename + '" />');
else if (navigator.appName == "Netscape")
document.writeln ('<embed src="' + filename + '" autostart="true"' +
' width="0" height="0" />');
</script>
|