音频 – HTML5麦克风捕获在Firefox中停止5秒钟

我正在使用getUserMedia()功能从麦克风捕获音频输入,在chrome中工作正常,但是在5秒钟之后,firefox声音就会消失。如果我再次发送麦克风请求(不重新加载页面)同样的事情发生。这是代码(我用 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);
});

有任何想法吗?

编辑/ UPDATE

谢谢你,csch,供参考。解决方案Karoun Kasraie工作!

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 },alert);

source

相关文章

HTML5和CSS3实现3D展示商品信息的代码
利用HTML5中的Canvas绘制笑脸的代码
Html5剪切板功能的实现
如何通过HTML5触摸事件实现移动端简易进度条
Html5移动端获奖无缝滚动动画实现
关于HTML5和CSS3实现机器猫的代码