WebRTC:是否可以控制麦克风和音量 [英] WebRTC: Is it possible to control the microphone and volume levels

查看:189
本文介绍了WebRTC:是否可以控制麦克风和音量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个演示网站,其中包含一个允许用户拨打电话的滑出式小部件。

I am working on a demo site which includes a slide-out widget that allows a user to place a call.

我正在使用SIPml5工具以及webrtc2sip后端用于处理呼叫。该部分全部设置并正常运行。所以现在我正在考虑是否可以使用窗口小部件中的滑块来控制麦克风和音量级别。这甚至可能吗?我在网上到处看都没有运气。

I am using the SIPml5 tool along with the webrtc2sip back end for handling the call. That part is all set up and properly working. So now I am looking at seeing if I can control the microphone and volume levels using sliders in the widget. Is this even possible? I look everywhere online and haven't had much luck.

我找到了一些网站,向我展示了如何在jQuery滑块中控制音频标签的音量码。所以我尝试设置如下代码:

I did find a couple sites that showed me how I can control the volume of the audio tag within the jQuery slider code. So I tried setting it up like the code below:

$(function() {
        $( "#slider-spkr" ).slider({
          orientation: "vertical",
          range: "min",
          min: 0,
          max: 100,
          value: 60,
          slide: function( event, ui ) {
            var value = $("#slider-spkr").slider("value");
            document.getElementById("audio_remote").volume = (value / 100);
          },
          change: function() {
            var value = $("#slider-spkr").slider("value");
            document.getElementById("audio_remote").volume = (value / 100);
          }
        });
    });

不幸的是,这也不起作用。因此,我不确定在使用SIPml5时是否允许这样做,或者我的jQ​​uery代码需要调整。

Unfortunately, this isn't working either. So I'm not sure if I am allowed to do this when using SIPml5, or if my jQuery code needs adjusted.

有没有其他人有运气添加麦克风/音量控制?感谢您的帮助。

Has anyone else had any luck with adding microphone/volume controls? Thanks for your help.

推荐答案

Afaik无法调整麦克风音量。但你可以使用stream api打开/关闭它:

Afaik it's impossible to adjust microphone volume. But you can switch it on/off by using stream api:

function toggleMic(stream) { // stream is your local WebRTC stream
  var audioTracks = stream.getAudioTracks();
  for (var i = 0, l = audioTracks.length; i < l; i++) {
    audioTracks[i].enabled = !audioTracks[i].enabled;
  }
}

此代码适用于原生webrtc api,而不是sipML5。看来他们还没有实现它。 这是收据不太明确。

This code is for native webrtc api, not sipML5. It seems they haven't implemented it yet. Here is not so clear receipt for it.

这篇关于WebRTC:是否可以控制麦克风和音量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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