MediaStream.onremovetrack - Web APIs 编辑
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()
).
Syntax
MediaStream.onremovetrack = eventHandler;
Value
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.
Example
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.textContent = `Removed: ${event.track.kind}: ${event.track.label}`;
trackList.appendChild(label);
};
Specifications
Specification | Status | Comment |
---|---|---|
Media Capture and Streams The definition of 'MediaStream.onremovetrack' in that specification. | Candidate Recommendation | Initial specification. |
Browser compatibility
BCD tables only load in the browser
See also
- The
removetrack
event and its type,MediaStreamTrackEvent
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论