W3cubDocs

/Web APIs

VideoTrackList: addtrack event

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

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

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
addtrack_event 37 7912–79 33 10 24 7 No 37 No No 7 No

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/VideoTrackList/addtrack_event