Web/API/MediaStream/getTrackById

From Get docs

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.

Syntax

var track = MediaStream.getTrackById(id);

Parameters

id
A DOMString which identifies the track to be returned.

Return value

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.

Example

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;

Specifications

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

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
getTrackById Chrome

Full support 26

Edge

Full support 12

Firefox

Full support 49

IE

No support No

Opera

No support No

Safari

Full support Yes

WebView Android

Full support 37

Chrome Android

Full support 26

Firefox Android

Full support 49

Opera Android

No support No

Safari iOS

Full support Yes

Samsung Internet Android

Full support 1.5

Legend

Full support  
Full support
No support  
No support


See also