如何在webrtc中静音/取消静音麦克风 [英] How to mute/unmute mic in webrtc

查看:2426
本文介绍了如何在webrtc中静音/取消静音麦克风的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从这里读到了如何在webrtc中为本地流静音/取消静音麦克风: WebRTC提示&诀窍

I have read from here that how i can mute/unmute mic for a localstream in webrtc:WebRTC Tips & Tricks

当我启动我的本地流麦克风时,默认启用,所以当我设置audioTracks [0] .enabled = false时在我的本地流中静音麦克风但是当我将其设置为真时它可以取消静音。以下是我对本地流的代码静音/取消静音:

When i start my localstream mic is enable at that time by default so when i set audioTracks[0].enabled=false it muted a mic in my local stream but when i set it back true it enable to unmute. Here is my code mute/unmute for a localstream:

 getLocalStream(function (stream,enable) {
        if (stream) {
            for (var i = 0; i < stream.getTracks().length; i++) {
                var track = stream.getAudioTracks()[0];
                if (track)
                    track.enabled = enable;
                //track.stop();
            }
        }
    });

有人可以建议我如何在本地流中取消麦克风。

Can someone suggest me how i can unmute mic back in a localstream.

推荐答案

我假设您的方法 getLocalStream 实际上正在调用 navigator.getUserMedia 。在这种情况下,当您执行此操作时,您将获得另一个流,而不是原始流。使用原始流你应该这样做

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.

您也可以查看 https://stackoverflow.com/a/35363284/1210071

这篇关于如何在webrtc中静音/取消静音麦克风的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆