HTML DOM Video muted 属性
HTML DOM Video muted 属性返回/设置一个布尔值,对应于视频音频是否静音。
语法
以下是该语法 −
返回布尔值 - 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://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>
输出
点击 ‘夜间’ 按钮 −
点击 ‘白天’ 按钮 −
广告