From 54ad57ea9527a58ac2b95159ed178ed7c737a89c Mon Sep 17 00:00:00 2001 From: diondiondion Date: Fri, 30 May 2025 17:26:08 +0200 Subject: [PATCH] fix: Fix autoplay not working properly in AudioModal, #34841 (#34865) --- app/javascript/mastodon/features/audio/index.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/javascript/mastodon/features/audio/index.tsx b/app/javascript/mastodon/features/audio/index.tsx index bff9013cdf..751af51b81 100644 --- a/app/javascript/mastodon/features/audio/index.tsx +++ b/app/javascript/mastodon/features/audio/index.tsx @@ -442,11 +442,14 @@ export const Audio: React.FC<{ if (typeof startMuted !== 'undefined') { audioRef.current.muted = startMuted; } + }, [setDuration, startTime, startVolume, startMuted]); + const handleCanPlayThrough = useCallback(() => { if (startPlaying) { - void audioRef.current.play(); + resumeAudio(); + void audioRef.current?.play(); } - }, [setDuration, startTime, startVolume, startMuted, startPlaying]); + }, [startPlaying, resumeAudio]); const seekBy = (time: number) => { if (!audioRef.current) { @@ -591,6 +594,7 @@ export const Audio: React.FC<{ onPause={handlePause} onProgress={handleProgress} onLoadedData={handleLoadedData} + onCanPlayThrough={handleCanPlayThrough} onTimeUpdate={handleTimeUpdate} onVolumeChange={handleVolumeChange} crossOrigin='anonymous'