This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2017.
The getTrackById() method of the MediaStream interface returns a MediaStreamTrack object representing the track with the specified ID string. If there is no track with the specified ID, this method returns null.
getTrackById(id)
idA string which identifies the track to be returned.
If a track is found for which MediaStreamTrack.id matches the specified id string, that MediaStreamTrack object is returned. Otherwise, the returned value is null.
This example activates a commentary track on a video by ducking the audio level of the main audio track to 50%, then enabling the commentary track.
stream.getTrackById("primary-audio-track").applyConstraints({ volume: 0.5 });
stream.getTrackById("commentary-track").enabled = true;
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
getTrackById |
26 | 12 | 49 | 15 | 11 | 26 | 49 | 14 | 11 | 1.5 | 37 | 11 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/MediaStream/getTrackById