HTML DOM MediaStream active Property

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

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:



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

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:

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

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Safari

full-stack-img




My Personal Notes arrow_drop_up

Small things always make you to think big

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.