Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> HTML

คุณสมบัติ muted ของ Video ใน HTML DOM

คุณสมบัติ muted ของ HTML DOM Video ใช้สำหรับคืนค่า หรือตั้งค่าค่า boolean ที่บ่งชี้ว่าวิดีโอจะมีเสียงถูกมิวตหรือไม่

ไวยากรณ์ (Syntax)

การคืนค่า Boolean (true/false)

mediaObject.muted

การตั้งค่า muted เป็น booleanValue

mediaObject.muted = booleanValue

ที่นี่ "booleanValue" สามารถเป็นค่าต่อไปนี้:

booleanValue รายละเอียด
true กำหนดให้วิดีโอมีเสียงถูกมิวต
false กำหนดให้วิดีโอไม่มีเสียงถูกมิวต

ตัวอย่างการใช้งาน

ตัวอย่างต่อไปนี้แสดงการใช้งานคุณสมบัติ Video muted:

<!DOCTYPE html> <html> <head> <title>HTML DOM Video muted</title> <style>    * {       padding: 2px;       margin:5px;    }    form {       width:70%;       margin: 0 auto;       text-align: center;    }    input[type="button"] {       border-radius: 10px;    } </style> </head> <body>    <form>         <fieldset>          <legend>HTML-DOM-Video-muted</legend>          <video id="demo" width="320" controls><source    src="https://www.tutorialspoint.com/html5/foo.mp4" type="video/mp4"></video><br>          <input type="button" onclick="getTrackDetails(1)" value="Day Time">          <input type="button" onclick="getTrackDetails(2)" value="Night Time">          <div id="divDisplay">          </div>         </fieldset>    </form> <script>    var divDisplay = document.getElementById("divDisplay");    var demo = document.getElementById("demo");    function getTrackDetails(val) {       if(val === 1){          demo.muted = false;          divDisplay.textContent = 'Its Day Time, so anyone will not get disturbed';       }       else{          demo.muted = true;          divDisplay.textContent = 'Its Night Time, so video will be on mute by default';       }    } </script> </body> </html>

ผลลัพธ์

คลิกปุ่ม 'Night Time':

คุณสมบัติ muted ของ Video ใน HTML DOM

คลิกปุ่ม 'Day Time':

คุณสมบัติ muted ของ Video ใน HTML DOM