The MediaStream.getTrackById() method 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.


var track = MediaStream.getTrackById(id);


A DOMString which identifies the track to be returned.

Return value

If a track is found for which 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;


Specification Status Comment
Media Capture and Streams
The definition of 'getTrackById()' in that specification.
Candidate Recommendation Initial specification.

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
getTrackByIdChrome Full support 26Edge Full support 12Firefox Full support 49IE No support NoOpera No support NoSafari Full support YesWebView Android Full support 37Chrome Android Full support 26Firefox Android Full support 49Opera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support 1.5


Full support  
Full support
No support  
No support

See also