MediaStream: getTrackById() method
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
.
Syntax
js
getTrackById(id)
Parameters
id
-
A string 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
.
Examples
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.
js
stream.getTrackById("primary-audio-track").applyConstraints({ volume: 0.5 });
stream.getTrackById("commentary-track").enabled = true;
Specifications
Specification |
---|
Media Capture and Streams # dom-mediastream-gettrackbyid |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
getTrackById |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.