Windows 10 reached EOS (end of support) on October 14, 2025. If you are on Windows 10, see this article.

Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

Cuireadh an snáithe seo sa chartlann. Cuir ceist nua má tá cabhair uait.

getUserMedia audio stream dies after about 5 seconds

  • 1 freagra
  • 6 leis an bhfadhb seo
  • 13 views
  • Freagra is déanaí ó velochy

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>

Réiteach roghnaithe

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

All Replies (1)

Réiteach Roghnaithe

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.