AudioTrackList: removetrack event
The removetrack
event is fired when a track is removed from an AudioTrackList
.
Syntax
Use the event name in methods like addEventListener()
, or set an event handler property.
addEventListener('removetrack', event => { })
onremovetrack = event => { }
Event type
An TrackEvent
. Inherits from Event
.
Event properties
TrackEvent
is based on Event
, so properties of Event
are also available on TrackEvent
objects.
track
Read only-
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
, orTextTrack
).
Description
Trigger
The removetrack
event is called whenever a track is removed from the media
element whose audio tracks are represented by the AudioTrackList
object.
This event is not cancelable and does not bubble.
Use cases
You can use this event to react to a new audio track becoming unavailable. You may want to update your UI elements to disallow for user selection of the removed audio track, for example.
Examples
Using addEventListener()
:
const videoElement = document.querySelector("video");
videoElement.audioTracks.addEventListener("removetrack", (event) => {
console.log(`Audio track: ${event.track.label} removed`);
});
Using the onremovetrack
event handler property:
const videoElement = document.querySelector("video");
videoElement.audioTracks.onremovetrack = (event) => {
console.log(`Audio track: ${event.track.label} removed`);
};
Specifications
Specification |
---|
HTML Standard # event-media-removetrack |
HTML Standard # handler-tracklist-onremovetrack |
Browser compatibility
BCD tables only load in the browser
See also
- Related events:
addtrack
,change
- This event on
VideoTrackList
targets:removetrack
- This event on
MediaStream
targets:removetrack
- Media Streams API
- WebRTC