mute event is sent to a MediaStreamTrack when the track's source is temporarily unable to provide media data. When the track is once again able to produce media output, an unmute event is sent.

During the time between the mute event and the unmute event, the value of the track's muted 特性为 true .

注意: The condition that most people think of as "muted" (that is, a user-toggled state of silencing a track) is actually managed using the MediaStreamTrack.enabled property, for which there are no events.

冒泡 No
可取消 No
接口 事件
事件处理程序特性 onmute

范例

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 referenced by 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 unmute event—the background color is restored to white.

还可以使用 onmute event handler property to set up a handler for this event; similarly, the onunmute event handler is available for setting up a handler for the unmute 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";
}
					

规范

规范 状态 注释
媒体捕获和流
The definition of 'mute' in that specification.
候选推荐 最初的规范。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
mute event Chrome Yes Edge 12 Firefox 59 IE No Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 59 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: