HTML5 Audio
HTML5 provides a standard for playing audio files.
Audio on the Internet
Until now, there is still no standard for playing audio on the web.
Today, most audio is played through plug-ins such as Flash. However, not all browsers have the same plug-in.
HTML5 specifies the standard for embedding audio elements on web pages, even with the < audio > element.
Browser support
Internet Explorer 9, Firefox, Opera, Chrome, and Safari all support <audio>
element。
Note: Internet Explorer 8 and earlier IE versions do not support <audio>
element。
HTML5 Audio-how to work
To play audio in HTML5, you need to use the following code:
Example
<audiocontrols><sourcesrc="horse.ogg"type="audio/ogg">
<sourcesrc="horse.mp3"type="audio/mpeg">Your browser does not support
audio element.</audio>
control
Property for adding playback, pause, and volume controls.
In <audio>
and </audio>
you need to insert something that the browser does not support. <audio>
the prompt text for the element.
<audio>
element allows you to use multiple <source>
element。 <source>
elements can be linked to different audio files, and the browser will use the first supported audio file
Audio format and browser support
Currently, the audio element supports three audio format files: MP3, Wav, and Ogg:
browser |
MP3 |
Wav |
Ogg |
---|---|---|---|
Internet Explorer 9 + |
YES |
NO |
NO |
Chrome 6 + |
YES |
YES |
YES |
Firefox 3.6 + |
YES |
YES |
YES |
Safari 5 + |
YES |
YES |
NO |
Opera 10 + |
YES |
YES |
YES |
MIME type of audio format
Format |
MIME-type |
---|---|
MP3 |
Audio/mpeg |
Ogg |
Audio/ogg |
Wav |
Audio/wav |
HTML5 Audio tag
Label |
Description |
---|---|
< audio > |
Defines the sound content |
<source> |
Defined multimedia resources, which can be multiple and used in<video>and<audio>tags |