2008年11月17日星期一

How to add background music to your HTML page


How to make your web site become more magnetic? What people normally will do is adding background music to the pages of web sites or blogs. Here is an introduction of how to add background music to your pages.


Erenow, I need to describe some shortcomings of using background music:

1. More bandwidth is needed. Of course, we can use the mp3 format instead of wav one which has smaller music file size, but more bandwidth is still needed than those general HTML pages.
2. W3C doesn't support "embed" tags.
3. Users can control the volume by hand, but adding background music will affect the browsing definitely.


By knowing about these, if you still want to do so. You need:

First of all, you should have a music file in mp3, wav or mid format. It also could be music file URL on the web. Whatever you choose, smaller size is always the best. Some people will recommend the URL one.

Then, we can embed it into pages with HTML code. Here, we use "embed" tags.



The code means: once a user open this page, the given background music would be loaded and played. When the music is finished, music is stopped. If you want to repeatly play this music, "loop" attribution could be input. If the value is set as true, the music will be repeated; if false, it will stop once finished. The code is like this:



Meanwhile, you can adjust the height and width of broadcaster:


Sometimes, this music player might breaks the layout of your web site. We can use "hidden" attribution to hide the music control panel to make it just play in background:


没有评论: