要使用
<code class="html"><audio src="path/to/your/audiofile.mp3" type="audio/mpeg"> Your browser does not support the audio element. </audio></code>
您還可以提供多個來源,以確保通過在
<code class="html"><audio> <source src="path/to/your/audiofile.mp3" type="audio/mpeg"> <source src="path/to/your/audiofile.ogg" type="audio/ogg"> Your browser does not support the audio element. </source></source></audio></code>
此方法允許瀏覽器選擇第一個支持的音頻格式。
HTML
audio/mpeg
。audio/ogg
。audio/wav
。audio/aac
。為了確保廣泛的兼容性,最好在
要使用controls
屬性。此屬性可以由瀏覽器提供的默認控件集(播放,暫停,音量和搜索)。這是您可以做到的:
<code class="html"><audio src="path/to/your/audiofile.mp3" type="audio/mpeg" controls> Your browser does not support the audio element. </audio></code>
controls
屬性是一個布爾屬性,這意味著您只需要將其包含在標籤中即可激活它。如果要自定義控件,則可能需要使用JavaScript和CSS來創建自定義播放器接口。
對於不支持HTML
<code class="html"><audio> <source src="path/to/your/audiofile.mp3" type="audio/mpeg"> <source src="path/to/your/audiofile.ogg" type="audio/ogg"> <p>Your browser does not support the audio element. You can <a href="path/to/your/audiofile.mp3">download the audio file</a> instead.</p> </source></source></audio></code>
在此示例中,具有不支持
<code class="html"><audio> <source src="path/to/your/audiofile.mp3" type="audio/mpeg"> <source src="path/to/your/audiofile.ogg" type="audio/ogg"> <object type="application/x-shockwave-flash" data="flashplayer.swf"> <param name="movie" value="flashplayer.swf"> <param name="flashvars" value="audioFile=path/to/your/audiofile.mp3"> <p>Your browser does not support the audio element or Flash. You can <a href="path/to/your/audiofile.mp3">download the audio file</a> instead.</p> </object> </source></source></audio></code>
這種全面的方法可確保用戶可以訪問音頻內容,無論其瀏覽器的功能如何。
以上是您如何使用&lt; audio&gt;如何將音頻嵌入HTML中 標籤?的詳細內容。更多資訊請關注PHP中文網其他相關文章!