Tags for this article: background music, html, internet explorer, tutorial
You can allow background music to be played every time an HTML file is accessed. There are two methods to do so. Both of the solutions described here – one for Microsoft’s Internet Explorer and the other for Netscape – are proprietary. As in both solutions do not belong to the HTML standard.
Moreover, if you wish to embed background music, you should know that it only annoys most users and will cause them to leave your website more quickly.
An Example:
<html>
<head>
<title>Background Music</title>
<bgsound src=“background.mid” loop= “infinite”>
</head>
<body>
<embed src=“background.mid” autostart=“true” loop=“true” hidden=“true” height=“0” width=“0”>
<h1>Page Content</h1>
</body>
</html>
Explanation:
With <bgsound …> you determine the background music in the HTML file header according to the Microsoft syntax for displaying the site. You achieve the same thing for Netscape with <embed …>. In both cases the src attribute determines the desired music file. The files should really be in either MID, AU or WAV formats. In order to prevent a visible display of the music player, the elements hidden= “true” height= “0” are necessary for the Netscape syntax. The automatic music start also has to be explicitly stated in the Netscape syntax – through autostart= “true”. Then you can determine if the music plays only once, multiple times, or continuously. You can also achieve an endless effect in the Microsoft syntax through loop= “infinite”. If you wish to limit the amount of times the music file is replayed, then replace infinite with this number. With the Netscape syntax you only have the choice between endless loop and no replay. In order to produce an endless loop, write loop= “true”. Otherwise you can simply do without the element.
Take Note:
In the upper example it is required that the music file is found in the same directory as the HTML file. If the file is another directory, then you must enter the relative or absolute path name. This works in the same way as embedding graphics.
Playing background music sets certain requirements for the visitor (such as having the right hardware, or speakers). Moreover, the web browser must also have the ability to control the music file playback.