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
相關用法
- jQuery UI Accordion active用法及代碼示例
- jQuery UI Tabs active用法及代碼示例
- HTML DOM lang用法及代碼示例
- HTML Style backgroundClip用法及代碼示例
- HTML Style borderTop用法及代碼示例
- HTML Meter max用法及代碼示例
- HTML Input Hidden value用法及代碼示例
- HTML Textarea autofocus用法及代碼示例
- HTML Style columnGap用法及代碼示例
- HTML Input Time autofocus用法及代碼示例
注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 HTML DOM MediaStream active Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。