HTML DOM Video defaultMuted Property


The HTML DOM Video defaultMuted property returns/sets boolean value corresponding to whether the video’s audio will be on mute by default or not.

NOTE − This property has no dynamic effect on HTML document but is just a reflection of the state of HTML DOM Video muted property.

Syntax

Following is the syntax −

Returning boolean value - true/false

mediaObject.defaultMuted

Setting defaultMuted to booleanValue

mediaObject.defaultMuted = booleanValue

Here, “booleanValue” can be the following −

booleanValue
Details
true
It definesthat video will have its audio on mute by default
false
It definesthat video will not have its audio on mute by default

Let us see an example of Video defaultMuted property −

Example

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM Video defaultMuted</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-defaultMuted</legend>
         <video id="demo" width="320" controls><source    src="http://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.defaultMuted = false;
         divDisplay.textContent = 'Its day time!';
      }
      else{
         demo.defaultMuted = true;
         divDisplay.textContent = 'Its night, so video will be on mute by default!';
      }
   }
</script>
</body>
</html>

Output

Clicking ‘Night Time’ button −

Clicking ‘Day Time’ button −

Updated on: 21-Dec-2021

75 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements