Javascript DOM HTML Video defaultMuted Property set

Introduction

Set the video to be muted by default:

document.getElementById("myVideo").defaultMuted = true;

View in separate window

<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<video id="myVideo" width="100" height="100" controls>
  <source src="video.mp4" type="video/mp4">
  <source src="video.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video><br>

<button onclick="getMuted()" type="button">Is the video muted by default?</button>
<button onclick="setToMuted()" type="button">Set video to be muted by default, and reload video</button>

<script>
var x = document.getElementById("myVideo");
function getMuted() {//ww w  . j  av  a  2  s.  co m
  document.getElementById("demo").innerHTML = x.defaultMuted;
}

function setToMuted() {
  x.defaultMuted = true;
  x.load()
}
</script>

</body>
</html>

The defaultMuted property sets or gets whether the video should be muted by default.

Setting this property will only change the default muted state, not the current.

To change the current muted state, use the muted property.

Property Values

Value Description
true Indicates that the video is muted by default
false Default. Indicates that the video is NOT muted by default

The defaultMuted property returns true if the video is muted by default, otherwise it returns false.




PreviousNext

Related