This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The getTracks()
method of the MediaStream
interface returns a sequence that represents all the MediaStreamTrack
objects in this stream's track set
, regardless of MediaStreamTrack.kind
.
Syntax
var mediaStreamTracks = mediaStream.getTracks()
Parameters
None.
Return value
An array of MediaStreamTrack
objects.
Example
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) })
Specifications
Specification | Status | Comment |
---|---|---|
Media Capture and Streams The definition of 'getTracks()' in that specification. |
Candidate Recommendation | Initial definition. |
Browser Compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
getTracks | Chrome Full support 45 | Edge Full support 12 | Firefox Full support Yes | IE No support No | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 45 | Chrome Android Full support 45 | Firefox Android Full support Yes | Opera Android No support No | Safari iOS Full support Yes | Samsung Internet Android Full support 5.0 |
Legend
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.
- Experimental. Expect behavior to change in the future.