mirror of
https://github.com/remvze/moodist.git
synced 2025-09-29 15:30:49 -04:00
fix: remove fading
This commit is contained in:
parent
663cb92135
commit
653d309e64
@ -1,4 +1,4 @@
|
|||||||
import { useMemo, useEffect, useCallback, useState, useRef } from 'react';
|
import { useMemo, useEffect, useCallback, useState } from 'react';
|
||||||
import { Howl } from 'howler';
|
import { Howl } from 'howler';
|
||||||
|
|
||||||
import { useLoadingStore } from '@/store';
|
import { useLoadingStore } from '@/store';
|
||||||
@ -11,7 +11,6 @@ export function useSound(
|
|||||||
const [hasLoaded, setHasLoaded] = useState(false);
|
const [hasLoaded, setHasLoaded] = useState(false);
|
||||||
const isLoading = useLoadingStore(state => state.loaders[src]);
|
const isLoading = useLoadingStore(state => state.loaders[src]);
|
||||||
const setIsLoading = useLoadingStore(state => state.set);
|
const setIsLoading = useLoadingStore(state => state.set);
|
||||||
const timeout = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
||||||
|
|
||||||
const { isBrowser } = useSSR();
|
const { isBrowser } = useSSR();
|
||||||
const sound = useMemo<Howl | null>(() => {
|
const sound = useMemo<Howl | null>(() => {
|
||||||
@ -50,35 +49,18 @@ export function useSound(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!sound.playing()) {
|
if (!sound.playing()) {
|
||||||
if (timeout.current) clearTimeout(timeout.current);
|
|
||||||
sound.volume(0);
|
|
||||||
sound.fade(
|
|
||||||
0,
|
|
||||||
typeof options.volume === 'number' ? options.volume : 0.5,
|
|
||||||
1000,
|
|
||||||
);
|
|
||||||
sound.play();
|
sound.play();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [src, setIsLoading, sound, hasLoaded, isLoading, options.volume]);
|
}, [src, setIsLoading, sound, hasLoaded, isLoading]);
|
||||||
|
|
||||||
const stop = useCallback(() => {
|
const stop = useCallback(() => {
|
||||||
if (sound) sound.stop();
|
if (sound) sound.stop();
|
||||||
}, [sound]);
|
}, [sound]);
|
||||||
|
|
||||||
const pause = useCallback(() => {
|
const pause = useCallback(() => {
|
||||||
if (sound) {
|
if (sound) sound.pause();
|
||||||
sound.fade(
|
}, [sound]);
|
||||||
typeof options.volume === 'number' ? options.volume : 0.5,
|
|
||||||
0,
|
|
||||||
1000,
|
|
||||||
);
|
|
||||||
|
|
||||||
timeout.current = setTimeout(() => {
|
|
||||||
sound.pause();
|
|
||||||
}, 1000);
|
|
||||||
}
|
|
||||||
}, [sound, options.volume]);
|
|
||||||
|
|
||||||
const control = useMemo(
|
const control = useMemo(
|
||||||
() => ({ isLoading, pause, play, stop }),
|
() => ({ isLoading, pause, play, stop }),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user