HTML5 Audio
HTML5 provides a standard for playing audio files.
Audio on the Internet
Until now, there was no standard for playing audio on web pages.
Today, most audio is played through plug-ins (such as Flash). However, not all browsers have the same plugins.
HTML5 specifies a standard for embedding audio elements on web pages, using the <audio> element.
Browser support
Internet Explorer 9+, Firefox, Opera, Chrome, and Safari all support the <audio> element.
Note: Internet Explorer 8 and earlier IE versions do not support the <audio> element.
HTML5 Audio - How it works
If required To play audio in HTML5, you need to use the following code:
Example
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <audio controls> <source src="horse.ogg" type="audio/ogg"> <source src="horse.mp3" type="audio/mpeg"> 您的浏览器不支持 audio 元素。 </audio> </body> </html>
Run Example»
Click "Run" Example" button to view the online example
control property for adding play, pause and volume controls.
Between <audio> and </audio> you need to insert the prompt text of the <audio> element that the browser does not support.
The<audio> element allows the use of multiple <source> elements. The <source> element can link different audio files, and the browser will use the first supported audio file
Audio formats and browser support
Currently, the <audio> element supports three audio format files: MP3, Wav, and Ogg:
browser | MP3 | Wav | Ogg |
---|---|---|---|
YES | NO | NO | |
YES | YES | YES | |
YES | YES | YES | |
YES | YES | NO | |
YES | YES | YES |
MIME type for audio format
MIME-type | |
---|---|
audio/mpeg | |
audio/ogg | |
audio/wav |
Tag | Description |
---|---|
<audio> ; | Defines the sound content |
Specifies the multimedia resource, which can be multiple, between <video> and Use |