📅  最后修改于: 2020-11-02 06:13:37             🧑  作者: Mango
HTML音频标签用于定义声音,例如音乐和其他音频片段。当前,HTML 5音频标签支持三种文件格式。
HTML5支持
下表定义了哪种Web浏览器支持哪种音频文件格式。
Browser | mp3 | wav | ogg |
---|---|---|---|
Internet Explorer | yes | no | no |
Google Chrome | yes | yes | yes |
Mozilla Firefox | yes* | yes | yes |
Opera | no | yes | yes |
Apple Safari | yes | yes | no |
让我们看看使用HTML音频标签播放mp3文件的代码。
输出:
让我们看一下使用HTML音频标签播放ogg文件的示例。
Element | Chrome | IE | Firefox | Opera | Safari |
Yes | Yes | Yes | Yes | Yes |
给出了HTML音频标签的列表。
Attribute | Description |
---|---|
controls | It defines the audio controls which is displayed with play/pause buttons. |
autoplay | It specifies that the audio will start playing as soon as it is ready. |
loop | It specifies that the audio file will start over again, every time when it is completed. |
muted | It is used to mute the audio output. |
preload | It specifies the author view to upload audio file when the page loads. |
src | It specifies the source URL of the audio file. |
在这里,我们将使用HTML音频标签的控件,自动播放,循环和src属性。
可用的MIME类型HTML音频标签如下所示。
Audio Format | MIME Type |
---|---|
mp3 | audio/mpeg |
ogg | audio/ogg |
wav | audio/wav |