Tuesday, January 7, 2014

Html>>Media >>Embedding Audio/Sound in background - (PART_43)

Topic: How to add or embed audio as background in html files?

Explanation:

EMBEDDING AUDIO:

It will be nice to hear a background music while working with html files. And now its simple to include an audio file into HTML page. There are different syntax for different browsers. For example, internet explorer support the BGSOUND and netstcape support an embed tag for embedding musics.

Free music downloads are available at various sites. Those websites will give us a trail to download and hear the music. We can just use those files in our html pages. In such cases, the embed tag is used much.

In Internet Explorer the audio can be included using <BGSOUND> tag. bgsound tag works only in IE and not in any other browsers.

Example Code:

<bgsound src="he-knows.wav" LOOP="-1" > 

The audio can be included using <embed> tag for netscape like browsers.

Example Code:

<EMBED SRC="he-knows.mp3" HIDDEN="true" AUTOSTART="true" LOOP="infinite" Height=145 width=160></EMBED> 

This will include backgound music into your webpage. If you want to display the controls in the browser, you can set the hidden attribute to false. Here in the above example we have used Loop=-1 which will play the file again and again. If you want to play it only once just set the loop to false.

IMPORTANT ATTRIBUTES OF EMBED:
  • SRC: This attribute takes the audio to the source URL.

  • WIDTH and HEIGHT: It manages the size of the plug-ins in html page.

  • AUTOSTART: Its value can be either TRUE or false
    TRUE: It will play the sound when the page loads.
    FALSE: It will wait for the user to click on the play button.

  • LOOP: The default value is FALSE which plays the file only once. Setting this to TRUE will play the sound continuously.

EMBEDDING BACKGROUND SOUND USING META:
Example Code:

<meta http-equiv="REFRESH" content="0;URL='ourmusic.wav'" > 

When you use the META tag element, the browser displays an dialog box which asks for what should firefox do with this file?. You can choose the player of your wish to play the song. For example, if you are opening with Windows Media Player then, the browser will take you to the windows Media player to play the song.

Using the Object TagApart from the non standard Embed tag, we can also use the <object> tag for embedding medias into our web pages. But, it is not still effective for cross-browser functions.You can specify some parameters related to the document with the param tag. IE sometimes needs a src parameter to understand the location

Example Code:
<object data="music.wav" type="audio/x-mplayer2" width="320" height="240">
<param name="src" value="music.wav">
<param name="autoplay" value="false">
<param name="autoStart" value="0">
Hear the sound : <a href="music.wav">music</a>
</object>
 

Type attribute specifies the application/media player type you are using.

Use the following type for your media player,
Windows Media Player : type="application/x-mplayer2".
Quicktime: type="video/quicktime".
RealPlayer: type="audio/x-pn-realaudio-plugin".


Result:
Hear the sound: music

The parameters
 autoplay is understandable by QuickTime, autoStart by Windows media Player and Real Audio.