aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/mediastream/getaudiotracks/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/api/mediastream/getaudiotracks/index.html')
-rw-r--r--files/zh-cn/web/api/mediastream/getaudiotracks/index.html78
1 files changed, 78 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/mediastream/getaudiotracks/index.html b/files/zh-cn/web/api/mediastream/getaudiotracks/index.html
new file mode 100644
index 0000000000..4c7bb6dad1
--- /dev/null
+++ b/files/zh-cn/web/api/mediastream/getaudiotracks/index.html
@@ -0,0 +1,78 @@
+---
+title: MediaStream.getAudioTracks()
+slug: Web/API/MediaStream/getAudioTracks
+tags:
+ - API
+ - getAudioTracks
+ - 媒体
+ - 媒体流
+ - 媒体流 API
+ - 媒体流轨道
+ - 方法
+ - 轨道
+ - 音频
+translation_of: Web/API/MediaStream/getAudioTracks
+---
+<p>{{APIRef("Media Capture and Streams")}}</p>
+
+<p>{{domxref("MediaStream")}} 接口下的 <strong><dfn><code>getAudioTracks()</code></dfn></strong> 方法会返回一个包含 <code><a href="https://www.w3.org/TR/mediacapture-streams/#track-set">track set</a></code> 流中所有 {{domxref("MediaStreamTrack.kind")}} 为 <code>audio</code> 的 {{domxref("MediaStreamTrack")}} 对象序列。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox">var <em>mediaStreamTracks</em> = <em>mediaStream</em>.getAudioTracks()</pre>
+
+<h3 id="参数">参数</h3>
+
+<p>无</p>
+
+<h3 id="返回值">返回值</h3>
+
+<p>{{domxref("MediaStreamTrack")}} 对象数组,包含流中所有的音轨。音轨的 {{domxref("MediaStreamTrack.kind", "kind")}} 值为 <code>audio</code> 。如果流中不包含音轨,则数组为空。</p>
+
+<div class="note">
+<p><strong>注意</strong>:数组中返回的顺序并不是由规范定义的,事实上,每次调用 <code>getAudioTracks()</code> 的结果都可能有所不同。</p>
+</div>
+
+<p>更早版本的本API中,包含一个用做列表中每个音频类型的 <code>AudioStreamTrack</code> 接口;现在已被合并至 {{domxref("MediaStreamTrack")}} 主接口中。</p>
+
+<h2 id="示例">示例</h2>
+
+<p><font><font>本示例使用 </font></font>{{domxref("MediaDevices.getUserMedia", "getUserMedia()")}} <font><font>获取视频流中的网络摄像机的音频和视频,并将媒体流绑定到 </font></font>{{HTMLElement("video")}} <font><font>元素,然后设置一个计时器,计时器到期时会停止在该媒体流中找到的第一个音轨。</font></font></p>
+
+<pre class="brush: js">navigator.mediaDevices.getUserMedia({audio: true, video: true})
+.then(mediaStream =&gt; {
+ document.querySelector('video').srcObject = mediaStream;
+ // Stop the audio stream after 5 seconds
+ setTimeout(() =&gt; {
+ const tracks = mediaStream.getAudioTracks()
+ 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-getaudiotracks','getAudioTracks()')}}</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.getAudioTracks")}}</p>