diff options
Diffstat (limited to 'files/zh-cn/web/api/mediastream/gettracks/index.html')
-rw-r--r-- | files/zh-cn/web/api/mediastream/gettracks/index.html | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/mediastream/gettracks/index.html b/files/zh-cn/web/api/mediastream/gettracks/index.html new file mode 100644 index 0000000000..c47d48473b --- /dev/null +++ b/files/zh-cn/web/api/mediastream/gettracks/index.html @@ -0,0 +1,65 @@ +--- +title: MediaStream.getTracks() +slug: Web/API/MediaStream/getTracks +tags: + - 参考 + - 媒体流 + - 媒体流 API + - 媒体轨道 + - 方法 +translation_of: Web/API/MediaStream/getTracks +--- +<p>{{APIRef("Media Capture and Streams")}}{{SeeCompatTable}}</p> + +<p>{{domxref("MediaStream")}} 接口的<strong><dfn><code>getTracks()</code></dfn></strong> 方法会返回一个包含 <code><a href="https://www.w3.org/TR/mediacapture-streams/#track-set">track set</a></code> 流中所有 {{domxref("MediaStreamTrack")}} 对象的序列, 序列内容与{{domxref("MediaStreamTrack.kind")}} 无关。</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">var <em>mediaStreamTracks</em> = <em>mediaStream</em>.getTracks()</pre> + +<h3 id="参数">参数</h3> + +<p>无</p> + +<h3 id="返回值">返回值</h3> + +<p>{{domxref("MediaStreamTrack")}} 对象的数组</p> + +<h2 id="示例">示例</h2> + +<pre class="brush: js">navigator.mediaDevices.getUserMedia({audio: false, video: true}) +.then(mediaStream => { + document.querySelector('video').srcObject = mediaStream; + // Stop the stream after 5 seconds + setTimeout(() => { + const tracks = mediaStream.getTracks() + tracks[0].stop() + }, 5000) +})</pre> + +<h2 id="说明">说明</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">说明</th> + <th scope="col">状态</th> + <th scope="col">评论</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('Media Capture','#dom-mediastream-gettracks','getTracks()')}}</td> + <td>{{Spec2('Media Capture')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器支持情况">浏览器支持情况</h2> + +<div class="hidden"> +<p>The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p> +</div> + +<p>{{Compat("api.MediaStream.getTracks")}}</p> |