The MediaStream.onremovetrack
property is an EventHandler
which specifies a function to be called when the removetrack
event occurs on a MediaStream
instance. This happens when a track of any kind is removed from the media stream. This event is fired when the browser removes a track from the stream (such as when a RTCPeerConnection
is renegotiated or a stream being captured using HTMLMediaElement.captureStream()
gets a new set of tracks because the media element being captured loaded a new source.
The removetrack
event does not get fired when JavaScript code explicitly removes tracks from the stream (by calling removeTrack()
).
MediaStream.onremovetrack = eventHandler;
This should be set to a function which you provide that accepts as input a MediaStreamTrackEvent
object representing the removetrack
event which has occurred. The MediaStreamTrack
representing the track which was removed is specified in the event's track
property.
This example adds a listener which, when a track is removed from the stream, logs the track that was removed.
stream.onremovetrack = function(event) { let trackList = document.getElementById("tracks"); let label = document.createElement("li"); label.innerHTML = "Removed: " + event.track.kind + ": " + event.track.label; trackList.appendChild(label); };
Specification | Status | Comment |
---|---|---|
Media Capture and Streams The definition of 'MediaStream.onremovetrack' in that specification. | Editor's Draft | Initial specification. |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | ? | No support | ? | ? | ? |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|
Basic support | ? | ? | No support | No support | ? | ? | (Yes) |
removetrack
event and its type, MediaStreamTrackEvent
.
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/MediaStream/onremovetrack