gpt4 book ai didi

javascript - 当 mediaStreamTrack.enabled 被修改时,如何接收通知/事件?

转载 作者:行者123 更新时间:2023-11-28 00:14:53 26 4
gpt4 key购买 nike

我正在使用 getUserMedia 来访问网络摄像头。我有一个功能可以打开和关闭视频,执行以下操作:

  var videoTracks = this.stream.getVideoTracks();
if (videoTracks.length === 0) {
trace('No local video available.');
return;
}

trace('Toggling video mute state.');
for (var i = 0; i < videoTracks.length; ++i) {
videoTracks[i].enabled = !videoTracks[i].enabled;
}

trace('Video ' + (videoTracks[0].enabled ? 'unmuted.' : 'muted.'));

enabled的值改变时如何接收事件?我尝试使用Object.observe,但它不起作用。

最佳答案

据我所知,当 enabled 属性更改时,当前没有触发/调用任何事件。

来自here :

Also, there is no "onmuted" and "onunmuted" event defined or fired in the WebRTC native implementations.

您可能必须自己构建此机制:

Keep in mind that you're disabling a media track locally; it will not fire any event on target users side. If you disabled video track; then it will cause "blank-video" on target-users side.

You can manually fire events like "onmuted" or "onmediatrackdisabled" by using socket that was used for signaling. You can send/emit messages like:

yourSignalingSocket.send({
isMediaStreamTrackDisabled: true,
mediaStreamLabel: stream.label
});

根据spec这最终应该成为 MediaStreamTrack 接口(interface)的一部分:

onmute of type EventHandler,

This event handler, of type mute, must be supported by all objects implementing the MediaStreamTrack interface.

我尝试在 Chrome (43) 中将一个函数分配给轨道的 onmute,但它从未被调用 ( looks like this is not implemented yet )。

关于javascript - 当 mediaStreamTrack.enabled 被修改时,如何接收通知/事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30547073/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com