Saturday, 19 September 2015

HTML Audio Tag Example

HTML Audio Tag Example

Let's see the code to play mp3 file using HTML audio tag.
  1. <audio controls>  
  2.   <source src="koyal.mp3" type="audio/mpeg">  
  3. Your browser does not support the html audio tag.  
  4. </audio>  

Output:
Let's see the example to play ogg file using HTML audio tag.
  1. <audio controls>  
  2.   <source src="koyal.ogg" type="audio/ogg">  
  3. Your browser does not support the html audio tag.  
  4. </audio>  

Supporting Browsers

Elementchrome browser Chromeie browser IEfirefox browser Firefoxopera browser Operasafari browser Safari
<audio>YesYesYesYesYes

Attributes of HTML Audio Tag

There is given a list of HTML audio tag.
AttributeDescription
controlsIt defines the audio controls which is displayed with play/pause buttons.
autoplayIt specifies that the audio will start playing as soon as it is ready.
loopIt specifies that the audio file will start over again, every time when it is completed.
mutedIt is used to mute the audio output.
preloadIt specifies the author view to upload audio file when the page loads.
srcIt specifies the source URL of the audio file.

HTML Audio Tag Attribute Example

Here we are going to use controls, autoplay, loop and src attributes of HTML audio tag.
  1. <audio controls autoplay loop>  
  2.   <source src="koyal.mp3" type="audio/mpeg"></audio>  


MIME Types for HTML Audio format

The available MIME type HTML audio tag is given below.
Audio FormatMIME Type
mp3audio/mpeg
oggaudio/ogg
wav

No comments:

Post a Comment