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

十年热恋 提交于 2019-12-03 05:01:21

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?

AudioContext.close() will release the hardware of the context, but check that it is available only for recent versions of chrome and firefox. Not available for IE aparently. Check the documentation: https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/close

Reference it to a variable i.e:
var myAudioCtx = new AudioContext();
Then destroy by calling
myAudioCtx.close();
That's it.

I was working on a media player widget which broke on Chrome (but not Firefox) as soon as more than five were embedded in a single page.

I discovered that you can create a single AudioContext and store it globally, then have each instance just use the shared AudioContext. It seems to work no differently - you can attach multiple buffers and multiple destinations and the audio all gets mixed together.

This might require more effort if you're using it for timing, but for playback of one or more audio streams generated on-the-fly with JS code, sharing a single AudioContext works fine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!