我用getUserMedia()函数从麦克风中捕获音频输入,在chrome中工作得很好,但在火狐中声音在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。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);
发布于 2014-05-06 13:39:03
这是Firefox中的一个bug,可以在这里找到:
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);
https://stackoverflow.com/questions/22860468
复制相似问题