JS启用&禁用麦克风

时间:2017-07-06 18:25:59

标签: javascript webrtc

我正在尝试在按下时启用和禁用我的麦克风,但我无法让它工作,我是javascript的新手。

感谢您的帮助.. PS我正在使用webrtc

navigator.getUserMedia({"audio":USE_AUDIO},
                function(stream) { /* user accepted access to a/v */
                    console.log("Access granted to audio/video");
                    local_media_stream = stream;
                    var local_media = $("<audio>");
                    local_media.attr("autoplay", "autoplay");
                    local_media.attr("muted", "true"); /* always mute ourselves by default */
                    local_media.attr("controls", "");
                    $('body').append(local_media);
                    attachMediaStream(local_media[0], stream);

                    if (callback) callback();

                    $('.testHold').mousedown(function() {
                      $('.tracker').html("holding holding holding");
                          local_media.attr("muted", "false");

                    }).bind('mouseup mouseleave', function() {
                      $('.tracker').text('Left the button');
                        local_media.attr("muted", "true");

                    });

                }

1 个答案:

答案 0 :(得分:0)

  $('.testHold').mousedown(function() {
                      $('.tracker').html("holding holding holding");
                      stream.getAudioTracks()[0].enabled = true;

                    }).bind('mouseup mouseleave', function() {
                      $('.tracker').text('Left the button');
                        stream.getAudioTracks()[0].enabled = false;

                    });