aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/mediastream/active/index.html
blob: 904001fd9cdbf084c00c5b395448bf7b7983bb9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
---
title: active
slug: Web/API/MediaStream/active
tags:
  - 参考
  - 媒体流
  - 属性
  - 接口
  - 活动
translation_of: Web/API/MediaStream/active
---
<p>{{APIRef("Media Capture and Streams")}}</p>

<p><strong><code>active</code></strong> 是 {{domxref("MediaStream")}} 接口的只读属性,返回布尔值,如果媒体流当前为活动状态时,返回 <code>true</code> ,否则返回 <code>false</code>。 至少有一条 {{domxref("MediaStreamTrack")}} 的媒体流不是{{domxref("MediaStreamTrack.ended")}} 状态时才认为是 <strong>活动的</strong> 。当所有轨道关闭时,媒体流的属性置为 <code>false。</code></p>

<h2 id="语法">语法</h2>

<pre class="syntaxbox">var <em>isActive</em> = <em>MediaStream</em>.active;</pre>

<h3 id="Value">Value</h3>

<p>布尔值,当媒体流当前为活动状态时为 <code>true</code> ; 否则为 <code>false</code>.</p>

<h2 id="样例">样例</h2>

<p>在这个例子中,使用{{domxref("MediaDevices.getUserMedia", "getUserMedia()")}}请求源为用户本地摄像机和麦克风的一条新流,当流可用时(即满足返回的{{jsxref("Promise")}}),根据该流当前是否处于活动状态来更新页面上的按钮。</p>

<pre class="brush: js">var promise = navigator.mediaDevices.getUserMedia({
  audio: true,
  video: true
});

promise.then(function(stream) {
  var startBtn = document.querySelector('#startBtn');
  startBtn.disabled = stream.active;
};)</pre>

<h2 id="规格">规格</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('Media Capture', '#dom-mediastream-active', 'active')}}</td>
   <td>{{Spec2('Media Capture')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容">浏览器兼容</h2>



<p>{{Compat("api.MediaStream.active")}}</p>