Video defaultMuted Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Video

Description

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

Set the defaultMuted property with the following Values

Value Description
true|false Sets whether the video should be muted by default.

Return Value

A Boolean, returns true if the video is muted by default, otherwise it returns false

Default Value is false

The following code shows how to Set the video to be muted by default:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<video id="myVideo" width="320" height="240" controls>
  <source src="your.mp4" type="video/mp4">
  <source src="your.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() {/*from   w ww  . j  a v  a 2 s . com*/
    console.log(x.defaultMuted);
}

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

</body>
</html>

Related Tutorials