當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。