joshwcomeau / use-sound

A React Hook for playing sound effects
MIT License
2.76k stars 98 forks source link

How to fade multiple audio samples #117

Closed JanVeb closed 2 years ago

JanVeb commented 2 years ago

How to fade multiple sounds?

Trying to figure out how to use use-sound for playing piano samples, seems as a good choice, though can't have sound on multiple mp3 imports

import s21 from './Piano/21.mp3'; import s60 from './Piano/60.mp3';

const [p21, { sound }] = useSound(s21, {}); const [p60, { sound }] = useSound(s60, {}); // Parsing error: Identifier 'sound' has already been declared

const n21 = () => { p21(); sound.fade(1, 0, 200); }; const n60 = () => { p60(); sound.fade(1, 0, 200); };

JanVeb commented 2 years ago

Found out solution for issues with howler, needed to move declaration of new howler instances out of react component, so I'm not looking for replacement anymore