From d3cb7795b7e654a2862f934b3877e3439deaab59 Mon Sep 17 00:00:00 2001 From: friday-bot Date: Tue, 14 Jul 2026 11:10:21 -0600 Subject: [PATCH] Handle video play() promise rejection with visible error state (closes #23) --- src/components/VideoPlayer.tsx | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/components/VideoPlayer.tsx b/src/components/VideoPlayer.tsx index c5a3e5a..de1682c 100644 --- a/src/components/VideoPlayer.tsx +++ b/src/components/VideoPlayer.tsx @@ -13,6 +13,7 @@ const VideoPlayer = ({ src, poster, vttSrc }: VideoPlayerProps) => { const [showCaptions, setShowCaptions] = useState(false) const [playbackRate, setPlaybackRate] = useState(1) const [progress, setProgress] = useState(0) + const [playError, setPlayError] = useState(false) const videoRef = useRef(null) const timeoutRef = useRef>(null) @@ -39,16 +40,23 @@ const VideoPlayer = ({ src, poster, vttSrc }: VideoPlayerProps) => { }, 3000) }, [isPlaying]) - const togglePlay = useCallback(() => { + const togglePlay = useCallback(async () => { if (videoRef.current) { if (isPlaying) { videoRef.current.pause() setShowControls(true) + setIsPlaying(false) } else { - videoRef.current.play() - hideControlsWithDelay() + try { + await videoRef.current.play() + setPlayError(false) + setIsPlaying(true) + hideControlsWithDelay() + } catch { + setIsPlaying(false) + setPlayError(true) + } } - setIsPlaying(!isPlaying) } }, [isPlaying, hideControlsWithDelay]) @@ -133,7 +141,15 @@ const VideoPlayer = ({ src, poster, vttSrc }: VideoPlayerProps) => { /> -
+

+ Video unavailable — please try again later. +

+
+ )} + +