How to mute/unmute mic in webrtc

依然范特西╮ 提交于 2019-12-01 05:39:37
Adrian Ber

I assume that your method getLocalStream is actually calling navigator.getUserMedia. In this case when you do this you'll get another stream, not the original one. Using the orignal stream you should do

mediaStream.getAudioTracks()[0].enabled = true; // or false to mute it.

Alternatively you can check https://stackoverflow.com/a/35363284/1210071

Ahhh there is a good way to do this:

mediaStream.getVideoTracks()[0].enabled = !(mediaStream.getVideoTracks()[0].enabled);

There are 2 properties enabled and muted. enabled is for setting, and muted is read-only on the remote side (the other person) (I have tried, setting muted does not work, basically, value cannot be changed)

stream.getAudioTracks()[0].enabled = true; // remote one will get muted change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!