The addtrack
event is fired when a new MediaStreamTrack
object has been added to a MediaStream
.
This event is not cancelable and does not bubble.
The addtrack
event is fired when a new MediaStreamTrack
object has been added to a MediaStream
.
This event is not cancelable and does not bubble.
Use the event name in methods like addEventListener()
, or set an event handler property.
js
addEventListener("addtrack", (event) => {}); onaddtrack = (event) => {};
A MediaStreamTrackEvent
. Inherits from Event
.
Also inherits properties from its parent interface, Event
.
MediaStreamTrackEvent.track
Read only
A MediaStreamTrack
object representing the track which was added to the stream.
Using addEventListener()
:
js
const stream = new MediaStream(); stream.addEventListener("addtrack", (event) => { console.log(`New ${event.track.kind} track added`); });
Using the onaddtrack
event handler property:
js
const stream = new MediaStream(); stream.onaddtrack = (event) => { console.log(`New ${event.track.kind} track added`); };
Specification |
---|
Media Capture and Streams # event-mediastream-addtrack |
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 |
26 | 12 | 50 | No | No | 11 | 4.4 | 26 | 50 | No | 11 | 1.5 |
removetrack
AudioTrackList
targets: addtrack
VideoTrackList
targets: addtrack
© 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/MediaStream/addtrack_event