问题描述
我有一些按钮,每个按钮播放不同的声音。我创建了一个滑块来更改每种声音的音量。但是当我改变声音的音量时,其他声音的音量也会改变。
我以这种方式创建每种声音:
const sound = new Howl({
src: `sounds/${filename}`,html5: true,loop: true,volume: 0.5
})
并将其添加到对象:
setActiveSounds([...activeSounds,{
fileName,sound,id: null,volume: 0.5 }])
{activeSounds.map(sound => {
return (
<input type="range" min="1" max="100" onChange={(e) => {
handelVolumeChange(e.target.value,sound)
}} />
)
}}
当滑块值更改时,此方法将运行:
const handelVolumeChange = (value,sound) => {
const newVolume = value/100
Howler.volume(newVolume.sound)
sound.volume = newVolume
}
我尝试在声音播放时向“ activeSounds”添加一个ID,并使用该ID更改音量,但它不起作用
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)