HTML <audio>แท็ก
ตัวอย่าง
เล่นไฟล์เสียง:
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio tag.
</audio>
ความหมายและการใช้งาน
แท็ ก<audio>
นี้ใช้เพื่อฝังเนื้อหาเสียงในเอกสาร เช่น เพลงหรือสตรีมเสียงอื่นๆ
<audio>
แท็กนี้มีแท็กตั้งแต่หนึ่งแท็กขึ้น
ไป<source>
ที่มีแหล่งที่มาของเสียงต่างกัน เบราว์เซอร์จะเลือกแหล่งที่มาแรกที่รองรับ
ข้อความระหว่าง แท็ก <audio>
และ</audio>
จะแสดงในเบราว์เซอร์ที่ไม่สนับสนุน<audio>
องค์ประกอบเท่านั้น
มีรูปแบบเสียงที่สนับสนุนสามรูปแบบใน HTML: MP3, WAV และ OGG
รูปแบบเสียงและการสนับสนุนเบราว์เซอร์
Browser | MP3 | WAV | OGG |
---|---|---|---|
Edge / IE | YES | YES* | YES* |
Chrome | YES | YES | YES |
Firefox | YES | YES | YES |
Safari | YES | YES | NO |
Opera | YES | YES | YES |
*จากขอบ79
เคล็ดลับและหมายเหตุ
เคล็ดลับ:สำหรับไฟล์วิดีโอ ให้ดูที่แท็ก
<video>
รองรับเบราว์เซอร์
ตัวเลขในตารางระบุเบราว์เซอร์รุ่นแรกที่สนับสนุนองค์ประกอบอย่างสมบูรณ์
Element | |||||
---|---|---|---|---|---|
<audio> | 4.0 | 9.0 | 3.5 | 4.0 | 11.5 |
คุณลักษณะ
Attribute | Value | Description |
---|---|---|
autoplay | autoplay | Specifies that the audio will start playing as soon as it is ready |
controls | controls | Specifies that audio controls should be displayed (such as a play/pause button etc) |
loop | loop | Specifies that the audio will start over again, every time it is finished |
muted | muted | Specifies that the audio output should be muted |
preload | auto metadata none |
Specifies if and how the author thinks the audio should be loaded when the page loads |
src | URL | Specifies the URL of the audio file |
คุณสมบัติสากล
แท็ ก<audio>
ยังสนับสนุน Global Attributes ในHTML
คุณสมบัติของเหตุการณ์
แท็ ก<audio>
ยังสนับสนุนแอตทริบิวต์เหตุการณ์ใน HTML
หน้าที่เกี่ยวข้อง
การอ้างอิง HTML DOM: การอ้างอิง DOM เสียง/วิดีโอ HTML
การตั้งค่า CSS เริ่มต้น
ไม่มี.