mirror of
https://github.com/remvze/moodist.git
synced 2025-12-17 08:54:13 +00:00
feat: add fading to intro and outro
This commit is contained in:
parent
32da26ccfc
commit
5467bbbc24
2 changed files with 23 additions and 4 deletions
|
|
@ -43,9 +43,9 @@ export function Sound({
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isSelected && isPlaying && functional) {
|
if (isSelected && isPlaying && functional) {
|
||||||
sound?.play();
|
sound?.fadeIn();
|
||||||
} else {
|
} else {
|
||||||
sound?.pause();
|
sound?.fadeOut();
|
||||||
}
|
}
|
||||||
}, [isSelected, sound, isPlaying, functional]);
|
}, [isSelected, sound, isPlaying, functional]);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,9 +62,28 @@ export function useSound(
|
||||||
if (sound) sound.pause();
|
if (sound) sound.pause();
|
||||||
}, [sound]);
|
}, [sound]);
|
||||||
|
|
||||||
|
const fadeIn = useCallback(() => {
|
||||||
|
if (sound) {
|
||||||
|
if (!sound.playing()) {
|
||||||
|
play();
|
||||||
|
sound.fade(0, options.volume || 0.5, 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [play, sound, options.volume]);
|
||||||
|
|
||||||
|
const fadeOut = useCallback(() => {
|
||||||
|
if (sound) {
|
||||||
|
sound.fade(options.volume || 0.5, 0, 1000);
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
sound.pause();
|
||||||
|
}, 1200);
|
||||||
|
}
|
||||||
|
}, [sound, options.volume]);
|
||||||
|
|
||||||
const control = useMemo(
|
const control = useMemo(
|
||||||
() => ({ isLoading, pause, play, stop }),
|
() => ({ fadeIn, fadeOut, isLoading, pause, play, stop }),
|
||||||
[play, stop, pause, isLoading],
|
[play, stop, pause, isLoading, fadeIn, fadeOut],
|
||||||
);
|
);
|
||||||
|
|
||||||
return control;
|
return control;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue