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
.
var mediaStreamTracks = mediaStream.getTracks()
None.
An array of MediaStreamTrack
objects.
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) })
Specification | Status | Comment |
---|---|---|
Media Capture and Streams The definition of 'getTracks()' in that specification. | Candidate Recommendation | Initial definition. |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | Yes | 12 | ? | ? | Yes | ? |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | Yes | Yes | Yes | ? | ? | ? | Yes |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/MediaStream/getTracks