13 November 2012

HTML5: audio tag

Hello everybody,

We will discuss about the audio tag in this post.
This tag is available in HTML 5.
You can play an audio file right in browser, and you can do that without using flash.

A note that I did not find anywhere is that not all browsers support mp3 files and not all browsers support wav files. This is why you need to have both mp3 and wav files.

So a cross browser solution - that will work on IE, Chrome, Firefox and Safari will be something like this:

<audio id="alert1" class="sound">
            <source src="~/Audio/notification1.mp3" type="audio/mpeg" />
   <source src="~/Audio/notification1.wav" type="audio/wav" />
            HTML5 audio not supported

To start playing an audio file you first need to pause it, set current time to 0 - so that when you call play it will start from the beginning (that is in case you intend to do that) and then you can call play.

Here is an example:

var oAudio = $('#audioTagID')[0];
    if (oAudio) {
        try {
            oAudio.currentTime = 0;
        } catch (e) {
That was a small intro for the audio tag from HTML 5.


garlie charls said...

HTML5 Development
is increasing area these days because of multiple and local programs that can be designed using it. Designers can come up with individual programs that provides useful functions

Web Development Services said...

HTML5 defines a new element defines a standard way to embed an audio file on a Web page: element . TYou have to insert content between and to insert the audio on your pages.

Buy Contact Lenses said...

Great article, Thanks for your great information, the content is quiet interesting. I will be waiting for your next post.

Post a Comment

your thoughts are welcome:

Need more? Leave comments and subscribe to my blog.