停止 Web Audio API 中的所有声音

问题描述:

我同时使用网络音频 api 加载并播放了多个声音.有没有办法阻止所有声音?

I loaded and played multiple sounds with web audio api at the same time. Is there any way to stop all sounds?

例如:现在停止所有声音的按钮.

ex: a button to stop all sounds now.

由于我同时播放了 10 个以上的声音,我不想为每个声源手动使用 noteOff(0) (或 stop(0) ).

Since I have more than 10 sounds playing at the same time, I dont wanna manually use noteOff(0) (or stop(0) ) for each sound source.

那么,实现你想要的效果的最简单方法是将它们全部 connect() 到一个增益节点,然后连接到目的地,并设置增益.增益.值 = 0.

The easiest way to achieve the effect you want, then, is to connect() them all to a gain node which is then connected to the destination, and set gain.gain.value = 0.

当然,它实际上不会阻止他们,但会使他们沉默.

It won't actually stop them, of course, but it will silence them.