joshwcomeau / use-sound

A React Hook for playing sound effects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to fade multiple audio samples

JanVeb opened this issue · comments

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);
};

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