Ian Hunter Ian Hunter - 1 month ago 24
Javascript Question

Failed to construct 'AudioContext': number of hardware contexts reached maximum

Is there a way to remove an

AudioContext
after I've created it?

var analyzers = [];
var contexts = [];

try {
for(var i = 0; i<20; i++) {
contexts[i] = new AudioContext();
analyzers[i] = contexts[i].createAnalyser();
}
}catch(e) {
console.log(e);
// too many contexts created -- how do I remove them?
}


I've tried this, but it doesn't let me create new contexts after the fact:
analyzers.forEach(function(analyzer){analyzer.disconnect(analyzer.context.destination)})


I am using Chrome 36 on Ubuntu Linux 14.04.

Answer

You should really only have one AudioContext in the page.

From the docs: "In most use cases, only a single AudioContext is used per document."

I can't really think of a reason why you'd ever need more than one. Is there a specific issue you've run into that caused you to create multiple contexts?

Comments