Fix: Properly handle async play() and remove autoPlay conflict

This commit is contained in:
Hördle Bot
2025-11-25 15:28:22 +01:00
parent f8b5dcf300
commit 9bf7e72a6c
2 changed files with 18 additions and 8 deletions

View File

@@ -53,13 +53,23 @@ const AudioPlayer = forwardRef<AudioPlayerRef, AudioPlayerProps>(({ src, unlocke
// Expose play method to parent component // Expose play method to parent component
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
play: () => { play: () => {
if (!audioRef.current || isPlaying) return; if (!audioRef.current) return;
audioRef.current.play();
setIsPlaying(true); const playPromise = audioRef.current.play();
onPlay?.(); if (playPromise !== undefined) {
if (!hasPlayedOnce) { playPromise
setHasPlayedOnce(true); .then(() => {
onHasPlayedChange?.(true); setIsPlaying(true);
onPlay?.();
if (!hasPlayedOnce) {
setHasPlayedOnce(true);
onHasPlayedChange?.(true);
}
})
.catch(error => {
console.error("Play failed:", error);
setIsPlaying(false);
});
} }
} }
})); }));

View File

@@ -271,7 +271,7 @@ export default function Game({ dailyPuzzle, genre = null, isSpecial = false, max
src={dailyPuzzle.audioUrl} src={dailyPuzzle.audioUrl}
unlockedSeconds={unlockedSeconds} unlockedSeconds={unlockedSeconds}
startTime={dailyPuzzle.startTime} startTime={dailyPuzzle.startTime}
autoPlay={lastAction === 'SKIP' || (lastAction === 'GUESS' && !hasWon && !hasLost) || hasPlayedAudio} autoPlay={lastAction === 'SKIP' || (lastAction === 'GUESS' && !hasWon && !hasLost)}
onReplay={addReplay} onReplay={addReplay}
onHasPlayedChange={setHasPlayedAudio} onHasPlayedChange={setHasPlayedAudio}
/> />