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.
addEventListener('addtrack', event => { })
onaddtrack = event => { }
Event type
An 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()
:
const videoElement = document.querySelector('video');
videoElement.videoTracks.addEventListener('addtrack', (event) => {
console.log(`Video track: ${event.track.label} added`);
});
Using the onaddtrack
event handler property:
const videoElement = document.querySelector('video');
videoElement.videoTracks.onaddtrack = (event) => {
console.log(`Video track: ${event.track.label} added`);
};
Specifications
Specification |
---|
HTML Standard # event-media-addtrack |
HTML Standard # handler-tracklist-onaddtrack |
Browser compatibility
BCD tables only load in the browser
See also
- Related events:
removetrack
,change
- This event on
AudioTrackList
targets:addtrack
- This event on
MediaStream
targets:addtrack
- Media Streams API
- WebRTC