首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在火狐中HTML5麦克风捕获在5秒后停止

在火狐中HTML5麦克风捕获在5秒后停止
EN

Stack Overflow用户
提问于 2014-04-04 18:38:48
回答 1查看 3K关注 0票数 17

我用getUserMedia()函数从麦克风中捕获音频输入,在chrome中工作得很好,但在火狐中声音在5秒后就消失了。如果我再次发送麦克风请求(没有重新加载页面),同样的事情也会发生。以下是代码(我使用http://updates.html5rocks.com/2012/09/Live-Web-Audio-Input-Enabled作为指导):

代码语言:javascript
复制
//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。Kasraie的变通方法起作用了!

代码语言:javascript
复制
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);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-06 13:39:03

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

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

还有一种变通方法:

代码语言:javascript
复制
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);

source

票数 19
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22860468

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档