当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


HTML DOM MediaStream active属性用法及代码示例


MediaStream active属性返回HTML文档中当前活动流的布尔值。该属性是只读的。如果流当前处于活动状态,则返回true,否则返回false。

用法:

var isActive = MediaStream.active;

返回值:此属性返回一个布尔值。

范例1:在此示例中,音频属性是允许的,视频属性是不允许的。

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>

输出:



范例2:在此的示例不允许音频属性和视频属性。

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>

输出:

范例3:在此示例中,音频属性和视频属性都被允许。

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>

输出:

支持的浏览器:

  • 谷歌浏览器
  • Edge
  • Firefox
  • Safari




相关用法


注:本文由纯净天空筛选整理自SHUBHAMSINGH10大神的英文原创作品 HTML DOM MediaStream active Property。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。