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 MediaStreamTrack.kind
.
Syntax
js
getTracks()
Parameters
None.
Return value
An array of MediaStreamTrack
objects.
Examples
js
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 |
---|
Media Capture and Streams # dom-mediastream-gettracks |
Browser compatibility
BCD tables only load in the browser