停止 Web Audio API 中的所有声音 [英] stop all sounds in Web Audio API

查看:40
本文介绍了停止 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.

这篇关于停止 Web Audio API 中的所有声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆