VideoTrackList: addtrack event
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
The addtrack
event is fired when a video track is added to a VideoTrackList
.
Syntax
Use the event name in methods like addEventListener()
, or set an event handler property.
js
addEventListener("addtrack", (event) => {});
onaddtrack = (event) => {};
Event type
A TrackEvent
. Inherits from Event
.
Event properties
In addition to the properties listed below, properties from the parent interface, Event
, are available.
track
Read only-
The newly-added
VideoTrack
the event is in reference to.
Examples
Using addEventListener()
:
js
const videoElement = document.querySelector("video");
videoElement.videoTracks.addEventListener("addtrack", (event) => {
console.log(`Video track: ${event.track.label} added`);
});
Using the onaddtrack
event handler property:
js
const videoElement = document.querySelector("video");
videoElement.videoTracks.onaddtrack = (event) => {
console.log(`Video track: ${event.track.label} added`);
};
Specifications
Specification |
---|
HTML # event-media-addtrack |
HTML # handler-tracklist-onaddtrack |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
addtrack event |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- User must explicitly enable this feature.
- Has more compatibility info.
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.
See also
- Related events:
removetrack
,change
- This event on
AudioTrackList
targets:addtrack
- This event on
MediaStream
targets:addtrack
- Media Capture and Streams API
- WebRTC