web api instance method
MediaStream: getTracks() method
The getTracks() method of the
MediaStream interface returns a sequence that represents all the
MediaStreamTrack objects in this
stream’s track set,
regardless of kind.
Syntax
getTracks()
Parameters
None.
Return value
An array of MediaStreamTrack objects.
Examples
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
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.