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:
<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>
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.Read this answer in context 3
Additional System Details
Application
- User Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/31.0.1650.63 Chrome/31.0.1650.63 Safari/537.36
More Information
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.