<audio controls>
<source src="example.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
在这个例子中,我们定义了一个元素,其中包含一个元素指定了音频文件的路径和类型。如果浏览器不支持标签,它会显示一条消息“Your browser does not support the audio element.”
2. 支持多种音频格式
标签可以包含多个元素,这样就可以支持多种音频格式。以下是一个支持不同格式的例子:
<audio controls>
<source src="example.mp3" type="audio/mpeg">
<source src="example.ogg" type="audio/ogg">
<source src="example.wav" type="audio/wav">
Your browser does not support the audio element.
</audio>
<audio controls>
<source src="example.mp3" type="audio/mpeg">
Your browser does not support the audio element. Here's a fallback:
<a href="example.mp3">Download audio file</a>
</audio>