diff --git a/app/src/components/AudioPlayer/AudioPlayer.tsx b/app/src/components/AudioPlayer/AudioPlayer.tsx index a03224c9..10323450 100644 --- a/app/src/components/AudioPlayer/AudioPlayer.tsx +++ b/app/src/components/AudioPlayer/AudioPlayer.tsx @@ -357,14 +357,22 @@ export function AudioPlayer() { } } - // Standard WaveSurfer auto-play - // Use a small delay to ensure audio element is fully ready - setTimeout(() => { - wavesurfer.play().catch((error) => { - debug.error('Failed to autoplay:', error); - // Don't show error for autoplay failures (browser restrictions) - }); - }, 100); + // Only auto-play if shouldAutoPlay flag is set (user explicitly clicked to play) + const shouldAutoPlayNow = usePlayerStore.getState().shouldAutoPlay; + if (shouldAutoPlayNow) { + // Clear the flag first + usePlayerStore.getState().clearAutoPlayFlag(); + + // Use a small delay to ensure audio element is fully ready + setTimeout(() => { + wavesurfer.play().catch((error) => { + debug.error('Failed to autoplay:', error); + // Don't show error for autoplay failures (browser restrictions) + }); + }, 100); + } else { + debug.log('Skipping auto-play - shouldAutoPlay is false'); + } }); // Handle play/pause diff --git a/app/src/components/History/HistoryTable.tsx b/app/src/components/History/HistoryTable.tsx index 85c7a8e4..418546b5 100644 --- a/app/src/components/History/HistoryTable.tsx +++ b/app/src/components/History/HistoryTable.tsx @@ -53,7 +53,7 @@ export function HistoryTable() { const exportGeneration = useExportGeneration(); const exportGenerationAudio = useExportGenerationAudio(); const importGeneration = useImportGeneration(); - const setAudio = usePlayerStore((state) => state.setAudio); + const setAudioWithAutoPlay = usePlayerStore((state) => state.setAudioWithAutoPlay); const restartCurrentAudio = usePlayerStore((state) => state.restartCurrentAudio); const currentAudioId = usePlayerStore((state) => state.audioId); const isPlaying = usePlayerStore((state) => state.isPlaying); @@ -77,9 +77,9 @@ export function HistoryTable() { if (currentAudioId === audioId) { restartCurrentAudio(); } else { - // Otherwise, load the new audio + // Otherwise, load the new audio and auto-play it const audioUrl = apiClient.getAudioUrl(audioId); - setAudio(audioUrl, audioId, profileId, text.substring(0, 50)); + setAudioWithAutoPlay(audioUrl, audioId, profileId, text.substring(0, 50)); } }; @@ -233,7 +233,11 @@ export function HistoryTable() { {/* Far right - Ellipsis actions */} -