Audio in HTML5

Some months ago when html5 was not published then audio file are used with plug-in in browser.But after HTML5 it is specified by <audio> element.

The audio element

To play an audio file specific element <audio> is used.Between the audio tag there <source> is used. Format is given below.

<audio>
<source src="xyx.mp3" type="audio/mpeg">
</audio>


Attributes of Audio tag.

Sr.No Attribute Description
1 autoplay This attribute is used for automatic starts of audio when the browser stop loading.
2 autobuffer This attribute used for automatic starts buffering a Audio.
3 controls This attribute is used for show and allow the user to use control of the Audio.
5 loop This attribute is used to allow a Audio to automatically seek back to the start after reaching at the end.
6 muted This attribute is used for mute a video or audio.

The autoplay attribute

<audio controls autoplay>
<source src="xyx.mp3" type="audio/mpeg">
</audio>

Explanation of autoplay attribute

As in above example autoplay attribute is used, this is for audio file to start playing automatically when url is loaded.


The autobuffer attribute

<audio autobuffer controls>
<source src="xyx.mp3" type="audio/mpeg">
</audio>

Explanation of autobuffer attribute

As in above example autobuffer attribute is used, this is for audio file to start buffering automatically when url is loaded.


The controls attribute

<audio controls>
<source src="xyx.mp3" type="audio/mpeg">
</audio>

Explanation of controls attribute

As in above example controls attribute is used, this for audio file to allow the user to have some controls on the audio file.


The loop attribute

<audio controls loop>
<source src="xyx.mp3" type="audio/mpeg">
</audio>

Explanation of loop attribute

As in above example loop attribute is used, this for audio file for repetation at some specific point.


The muted attribute

<audio controls muted>
<source src="xyx.mp3" type="audio/mpeg">
</audio>

Explanation of muted attribute

As in above example muted attribute is used, this for audio file for mute a audio or video file.


Audio Formats

Sr.No Format Description
1 .mp4 .mp4 is used both in audio and video.
2 .mp3 .mp3 formate is most popular formate in music due his amamzing functionalities.
3 .ogg This is another formate for music.This is also supported in HTML and HTML5.
4 .wav This is another common formate of audio formate which supported both in HTML and HTML5.
5 .aac This is used on apple devices especially and not supported in web browsers.
6 .wma This is most famous in microsoft devices but not supported in web browsers









The Best

Comment here

If you have any query, if you want to know something about any of technical course related to computer science field, if you have any suggestion about relevant to uploaded content or if you anything wrong here (any mistake in content) than please contact us. Keep in mind, comment should be according to community guidelines.