Open In App

HTML DOM MediaStream active Property

Last Updated : 30 Jul, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The MediaStream active property returns the Boolean value for currently active stream in the HTML document. This property is read-only. If the stream is currently active then it returns true otherwise, it returns false.

Syntax:

var isActive = MediaStream.active;

Return value: This property return a Boolean value.

Example 1: In this example, the audio property is allowed and video property is not allowed.

HTML




<!DOCTYPE HTML>
<html>
  
<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
      
    <h3>
        HTML | MediaStream active property
    </h3>
  
    <button onclick="Geeks()">
        click here
    </button>
  
    <h2 id="GFG_DOWN"></h2>
  
    <script>
        function Geeks() {
            var gumStream;
            var el_down = document.getElementById("GFG_DOWN");
            var gumStream = "x";
            navigator.getUserMedia({ audio: true, video: false },
                function (stream) {
                    gumStream = stream;
                    el_down.innerHTML = gumStream.active;
                },
                function (error) {
                    console.log('getUserMedia() error', error);
                });
        }
    </script>
</body>
  
</html>


Output:

Example 2: In this example, the audio property is not allowed and video property is allowed.

HTML




<!DOCTYPE HTML>
<html>
  
<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
      
    <h3>
        HTML | MediaStream active property
    </h3>
  
    <button onclick="Geeks()">
        click here
    </button>
  
    <h2 id="GFG_DOWN"></h2>
  
    <script>
        function Geeks() {
            var gumStream;
            var el_down = document.getElementById("GFG_DOWN");
            var gumStream = "x";
            navigator.getUserMedia({ audio: false, video: true },
                function (stream) {
                    gumStream = stream;
                    el_down.innerHTML = gumStream.active;
                },
                function (error) {
                    console.log('getUserMedia() error', error);
                });
        }
    </script>
</body>
  
</html>


Output:

Example 3: In this example, both the audio property and video property are allowed.

HTML




<!DOCTYPE HTML> 
<html
    
<body style="text-align:center;"
    <h1 style="color:green;"
        GeeksForGeeks 
    </h1
    <h3
        HTML | MediaStream active property
    </h3
    
    <button onclick="Geeks()"
        click here 
    </button
      
    <h2 id="GFG_DOWN"></h2
      
    <script
    function Geeks() { 
        var gumStream;
        var el_down = document.getElementById("GFG_DOWN"); 
        var gumStream = "x";
        navigator.getUserMedia({audio: true, video: true},
            function(stream) {
                 gumStream = stream;
                 el_down.innerHTML = gumStream.active;
            },
            function(error) {
                console.log('getUserMedia() error', error);
            });
    }
    </script
</body
  
</html>


Output:

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Safari


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads