The TrackEvent interface, which is part of the HTML DOM specification, is used for events which represent changes to a set of available tracks on an HTML media element; these events are addtrack and removetrack.
It's important not to confuse TrackEvent with the RTCTrackEvent interface, which is used for tracks which are part of an RTCPeerConnection.
Events based on TrackEvent are always sent to one of the media track list types:
The DOM track object the event is in reference to. If not null, this is always an object of one of the media track types: AudioTrack, VideoTrack, or TextTrack).
Instance methods
TrackEvent has no methods of its own; however, it is based on Event, so it provides the methods available on Event objects.
Example
This example sets up a function, handleTrackEvent(), which is called for any addtrack or removetrack event on the first <video> element found in the document.
The event handler uses the JavaScript instanceof operator to determine which type of track the event occurred on, then outputs to console a message indicating what kind of track it is and whether it's being added to or removed from the element.