MediaStreamTrack: unmute event - Web APIs 编辑
The unmute
event is sent to a MediaStreamTrack
when the track's source is once again able to provide media data after a period of not being able to do so. This ends the muted
state that began with the mute
event.
Bubbles | No |
---|---|
Cancelable | No |
Interface | Event |
Event handler property | onunmute |
Note: The condition that most people think of as "muted" (that is, a user-controllable way to silence a track) is actually managed using the MediaStreamTrack.enabled
property, for which there are no events.
Examples
In this example, event handlers are established for the mute
and unmute
events in order to detect when the media is not flowing from the source for the MediaStreamTrack
stored in the variable musicTrack
.
musicTrack.addEventListener("mute", event => {
document.getElementById("timeline-widget").style.backgroundColor = "#aaa";
}, false);
musicTrack.addEventListener("unmute", event => {
document.getElementById("timeline-widget").style.backgroundColor = "#fff";
}, false);
With these event handlers in place, when the track musicTrack
enters its muted
state, the element with the ID timeline-widget
gets its background color changed to #aaa
. When the track exits the muted state—detected by the arrival of an unmuted
event—the background color is restored to white.
You can also use the onunmute
event handler property to set up a handler for this event; similarly, the onmute
event handler is available for setting up a handler for the mute
event. The following example shows this:
musicTrack.onmute = event => {
document.getElementById("timeline-widget").style.backgroundColor = "#aaa";
}
musicTrack.mute = event = > {
document.getElementById("timeline-widget").style.backgroundColor = "#fff";
}
Specifications
Specification | Status | Comment |
---|---|---|
Media Capture and Streams The definition of 'unmute' in that specification. | Candidate Recommendation | Initial specification. |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论