WebRTC - 如何静音本地音频输出 [英] WebRTC - How to mute local audio output

查看:792
本文介绍了WebRTC - 如何静音本地音频输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试仅将WebRTC中的本地音频播放静音,更具体地说,在getUserMedia()之后以及在建立任何服务器连接之前。我发现的任何选项都没有;来自Muaz Khan的这个失败了:

I'm trying to mute only the local audio playback in WebRTC, more specifically after getUserMedia() and prior to any server connection being made. None of the options I've found work; this one from Muaz Khan fails:

var audioTracks = localMediaStream.getAudioTracks();
// if MediaStream has reference to microphone
if (audioTracks[0]) {
    audioTracks[0].enabled = false;
}

来源

这项技术也是此处描述为正常工作,但在Chrome版本39.0.2171.95(64位)上失败)(Ubuntu 14.04)。

This technique is also described here as "working", but fails here on Chrome Version 39.0.2171.95 (64-bit) (Ubuntu 14.04).

据说通过使用音量增益工作的其他方法:

Additional method that is said to work by using volume gain:

window.AudioContext = window.AudioContext || window.webkitAudioContext;
var audioContext = new AudioContext();
var source = audioContext.createMediaStreamSource(clientStream);
var volume = audioContext.createGain();
source.connect(volume);
volume.connect(audioContext.destination);
volume.gain.value = 0;  //turn off the speakers

tl; dr我不想听到麦克风的输入在我的扬声器上,但我确实想看到我的视频图像。

tl;dr I don't want to hear the input from my microphone on my speakers, but I do want to see my video image.

解决方法

这个解决方法是由 Benjamin Trent 建议的,它通过在视频标签上设置静音属性来静音音频所以:

This workaround was suggested by Benjamin Trent and it mutes the audio by setting the muted attribute on the video tag like so:

document.getElementById("html5vid").muted = true;

也是类似的问题,但它的视频,所以不一样

推荐答案

将此作为答案添加,因为它是事实上的正确答案:

Adding this as the answer because it is the de facto correct answer:

您所说的解决方法是许多主要WebRTC视频平台使用的内容:

What you stated as a workaround is what's used by many major WebRTC Video platforms:

navigator.mediaDevices.getUserMedia({ video: true, audio: true })
  .then(stream => {
    const vid = document.getElementById('html5vid');
    vid.autoplay = true;
    vid.muted = true;
    vid.srcObject = stream;
  });

这篇关于WebRTC - 如何静音本地音频输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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