diff --git a/components/AudioPlayer.tsx b/components/AudioPlayer.tsx index c7e88d1..115ef8e 100644 --- a/components/AudioPlayer.tsx +++ b/components/AudioPlayer.tsx @@ -53,13 +53,23 @@ const AudioPlayer = forwardRef(({ src, unlocke // Expose play method to parent component useImperativeHandle(ref, () => ({ play: () => { - if (!audioRef.current || isPlaying) return; - audioRef.current.play(); - setIsPlaying(true); - onPlay?.(); - if (!hasPlayedOnce) { - setHasPlayedOnce(true); - onHasPlayedChange?.(true); + if (!audioRef.current) return; + + const playPromise = audioRef.current.play(); + if (playPromise !== undefined) { + playPromise + .then(() => { + setIsPlaying(true); + onPlay?.(); + if (!hasPlayedOnce) { + setHasPlayedOnce(true); + onHasPlayedChange?.(true); + } + }) + .catch(error => { + console.error("Play failed:", error); + setIsPlaying(false); + }); } } })); diff --git a/components/Game.tsx b/components/Game.tsx index a547f73..a5b6dc7 100644 --- a/components/Game.tsx +++ b/components/Game.tsx @@ -271,7 +271,7 @@ export default function Game({ dailyPuzzle, genre = null, isSpecial = false, max src={dailyPuzzle.audioUrl} unlockedSeconds={unlockedSeconds} startTime={dailyPuzzle.startTime} - autoPlay={lastAction === 'SKIP' || (lastAction === 'GUESS' && !hasWon && !hasLost) || hasPlayedAudio} + autoPlay={lastAction === 'SKIP' || (lastAction === 'GUESS' && !hasWon && !hasLost)} onReplay={addReplay} onHasPlayedChange={setHasPlayedAudio} />