HTML5 麦克风捕获在 Firefox 中 5 秒后停止



我正在使用getUserMedia()功能从麦克风捕获音频输入,在chrome中工作正常,但在Firefox中声音在5秒后消失。如果我再次发送麦克风请求(不重新加载页面),也会发生同样的事情。这是代码(我使用 http://updates.html5rocks.com/2012/09/Live-Web-Audio-Input-Enabled 作为指导):

//getting the function depending on browser
navigator.getMedia = ( navigator.getUserMedia ||
                       navigator.webkitGetUserMedia ||
                       navigator.mozGetUserMedia ||
                       navigator.msGetUserMedia);
// success callback when requesting audio input stream
function gotAudioStream(stream) {
    window.AudioContext = window.AudioContext || window.webkitAudioContext;
    var audioContext = new AudioContext();
    // Create an AudioNode from the stream.
    var mediaStreamSource = audioContext.createMediaStreamSource( stream );
    // Connect it to the destination to hear yourself (or any other node for processing!)
    mediaStreamSource.connect( audioContext.destination );
}

function gotError(err) {
      alert("An error occured! " + err);
}

//when button clicked, browser asks a permission to access microphone
jQuery("#sound_on").click(function()
{
    navigator.getMedia({audio: true},gotAudioStream,gotError);
});

有什么想法吗?


编辑/更新

谢谢你,csch,参考。卡龙·卡斯莱的解决方法奏效了!

context = new AudioContext();
navigator.getUserMedia({ audio: true }, function(stream) {
  // the important thing is to save a reference to the MediaStreamAudioSourceNode
  // thus, *window*.source or any other object reference will do
  window.source = context.createMediaStreamSource(stream);
  source.connect(context.destination);
}, alert);

这是 Firefox 中的一个错误,可以在这里找到:

https://bugzilla.mozilla.org/show_bug.cgi?id=934512

还有一个解决方法:

context = new AudioContext();
navigator.getUserMedia({ audio: true }, function(stream) {
  // the important thing is to save a reference to the MediaStreamAudioSourceNode
  // thus, *window*.source or any other object reference will do
  window.source = context.createMediaStreamSource(stream);
  source.connect(context.destination);
}, alert);

相关内容

  • 没有找到相关文章

最新更新