--- title: MediaStream.addTrack() slug: Web/API/MediaStream/addTrack translation_of: Web/API/MediaStream/addTrack original_slug: Web/API/MediaStream.addTrack ---

{{APIRef("Media Capture and Streams")}}

MediaStream.addTrack() 方法会给流添加一个新轨道。指定一个{{domxref("MediaStreamTrack")}}对象作为参数。

如果指定的track已经存在于流的track set里的话,该方法不会产生作用。

语法

stream.addTrack(track);

Parameters

track
A {{domxref("MediaStreamTrack")}} to add to the stream.

Example

 

Specifications

Specification Status Comment
{{ SpecName('Media Capture','#widl-MediaStream-addTrack-void-MediaStreamTrack-track','addTrack()') }} {{ Spec2('Media Capture') }} Initial specification.

Browser compatibility

{{ CompatibilityTable() }}

{{ CompatUnknown() }}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{ CompatVersionUnknown() }} {{ CompatGeckoDesktop(34) }} {{ CompatNo() }} {{ CompatVersionUnknown() }} {{ CompatUnknown() }}
addTrack() and {{domxref("removeTrack()")}} {{ CompatUnknown() }} {{CompatGeckoDesktop(44)}} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatGeckoMobile(34) }} {{ CompatNo() }} {{ CompatUnknown() }} {{ CompatUnknown() }}
addTrack() and {{domxref("removeTrack()")}} {{ CompatUnknown() }} {{CompatGeckoDesktop(44)}} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}

See also