Skip to content

Commit

Permalink
fix: remove extra play calls
Browse files Browse the repository at this point in the history
  • Loading branch information
remvze committed Nov 28, 2023
1 parent cf7600e commit e0164c3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/hooks/use-sound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ export function useSound(

const play = useCallback(() => {
if (sound) {
if (!hasLoaded) {
if (!hasLoaded && !isLoading) {
setIsLoading(true);
sound.load();
}

sound.play();
if (!sound.playing()) {
sound.play();
}
}
}, [sound, hasLoaded]);
}, [sound, hasLoaded, isLoading]);

const stop = useCallback(() => {
if (sound) sound.stop();
Expand Down

0 comments on commit e0164c3

Please sign in to comment.