This thread was archived.
Please ask a new question if you need help.
Solved
Archived
getUserMedia audio stream dies after about 5 seconds
After about 5 seconds of working correctly, the audio icon disappears on the address bar and the stream becomes constantly zero.
HTML to reproduce:
After about 5 seconds of working correctly, the audio icon disappears on the address bar and the stream becomes constantly zero.
HTML to reproduce:
<!DOCTYPE html>
<html>
<body>
<script>
function gotStream(stream) {
var audioContext = new AudioContext();
var input = audioContext.createMediaStreamSource(stream);
var node = audioContext.createScriptProcessor(4096,2 ,2);
node.onaudioprocess = function(e) {
var vals = e.inputBuffer.getChannelData(0);
console.log("MAX",Math.max.apply(Math,vals),"MIN",Math.min.apply(Math,vals));
};
input.connect(node);
var zeroGain = audioContext.createGain();
zeroGain.gain.value = 0;
node.connect(zeroGain);
zeroGain.connect(audioContext.destination);
};
var analyserContext = false;
function initAudio() {
if (!navigator.getUserMedia)
navigator.getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
navigator.getUserMedia({audio:true}, gotStream, function(e) {
alert('Error getting audio');
console.log(e);
});
}
window.addEventListener('load', initAudio );
</script>
</body></html>
All Replies (1)
Chosen Solution
After noticing not all web audio apps suffer from this problem, I started digging around, and found this behavior to be related to scoping (!).
Basically - it seems that at least one part of the audio pipeline needs to be global for it to keep on working. For instance, adding
window.horrible_hack_for_mozilla = input;
before " var node =" fixes the behavior.