Fix: Start button now actually starts audio playback

This commit is contained in:
Hördle Bot
2025-11-25 15:26:20 +01:00
parent 072158f4ed
commit f8b5dcf300
2 changed files with 31 additions and 6 deletions

View File

@@ -1,7 +1,7 @@
'use client';
import { useEffect, useState } from 'react';
import AudioPlayer from './AudioPlayer';
import { useEffect, useState, useRef } from 'react';
import AudioPlayer, { AudioPlayerRef } from './AudioPlayer';
import GuessInput from './GuessInput';
import Statistics from './Statistics';
import { useGameState } from '../lib/gameState';
@@ -38,6 +38,7 @@ export default function Game({ dailyPuzzle, genre = null, isSpecial = false, max
const [hasRated, setHasRated] = useState(false);
const [showYearModal, setShowYearModal] = useState(false);
const [hasPlayedAudio, setHasPlayedAudio] = useState(false);
const audioPlayerRef = useRef<AudioPlayerRef>(null);
useEffect(() => {
const updateCountdown = () => {
@@ -119,7 +120,8 @@ export default function Game({ dailyPuzzle, genre = null, isSpecial = false, max
const handleStartAudio = () => {
// This will be called when user clicks "Start" button on first attempt
// We'll trigger the audio player programmatically
// Trigger the audio player to start playing
audioPlayerRef.current?.play();
setHasPlayedAudio(true);
};
@@ -265,6 +267,7 @@ export default function Game({ dailyPuzzle, genre = null, isSpecial = false, max
<ScoreDisplay score={gameState.score} breakdown={gameState.scoreBreakdown} />
<AudioPlayer
ref={audioPlayerRef}
src={dailyPuzzle.audioUrl}
unlockedSeconds={unlockedSeconds}
startTime={dailyPuzzle.startTime}