From 5870cde6148c7e7df66e63f37802d9c067db0691 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Wed, 13 Mar 2024 14:15:10 -0600 Subject: [PATCH] Fix error checking --- web/src/components/player/HlsVideoPlayer.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/web/src/components/player/HlsVideoPlayer.tsx b/web/src/components/player/HlsVideoPlayer.tsx index cdbd73cdc..98be56e2a 100644 --- a/web/src/components/player/HlsVideoPlayer.tsx +++ b/web/src/components/player/HlsVideoPlayer.tsx @@ -43,6 +43,7 @@ export default function HlsVideoPlayer({ // playback const hlsRef = useRef(); + const [useHlsCompat, setUseHlsCompat] = useState(false); useEffect(() => { if (!videoRef.current) { @@ -52,8 +53,7 @@ export default function HlsVideoPlayer({ if (videoRef.current.canPlayType(HLS_MIME_TYPE)) { return; } else if (Hls.isSupported()) { - hlsRef.current = new Hls(); - hlsRef.current.attachMedia(videoRef.current); + setUseHlsCompat(true); } }, [videoRef]); @@ -64,15 +64,20 @@ export default function HlsVideoPlayer({ const currentPlaybackRate = videoRef.current.playbackRate; - if (!hlsRef.current) { + if (!useHlsCompat) { videoRef.current.src = currentSource; videoRef.current.load(); return; } + if (!hlsRef.current) { + hlsRef.current = new Hls(); + hlsRef.current.attachMedia(videoRef.current); + } + hlsRef.current.loadSource(currentSource); videoRef.current.playbackRate = currentPlaybackRate; - }, [videoRef, hlsRef, currentSource]); + }, [videoRef, hlsRef, useHlsCompat, currentSource]); // controls @@ -186,8 +191,7 @@ export default function HlsVideoPlayer({ e.target.error.code == MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED && videoRef.current ) { - hlsRef.current = new Hls(); - hlsRef.current.attachMedia(videoRef.current); + setUseHlsCompat(true); } }} />