From 56ed9b0fca90803f3d6a19189a87b88c52bd0aad Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Wed, 17 Jul 2024 07:32:52 -0600 Subject: [PATCH] Fix buffering --- web/src/components/player/HlsVideoPlayer.tsx | 31 ++++++++++++-------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/web/src/components/player/HlsVideoPlayer.tsx b/web/src/components/player/HlsVideoPlayer.tsx index c9f63f96d..5f499ade7 100644 --- a/web/src/components/player/HlsVideoPlayer.tsx +++ b/web/src/components/player/HlsVideoPlayer.tsx @@ -268,11 +268,30 @@ export default function HlsVideoPlayer({ onPlaying={onPlaying} onPause={() => { setIsPlaying(false); + clearTimeout(bufferTimeout); if (isMobile && mobileCtrlTimeout) { clearTimeout(mobileCtrlTimeout); } }} + onWaiting={() => { + if (onError != undefined) { + if (videoRef.current?.paused) { + return; + } + + setBufferTimeout( + setTimeout(() => { + if ( + document.visibilityState === "visible" && + videoRef.current + ) { + onError("stalled"); + } + }, 3000), + ); + } + }} onProgress={() => { if (onError != undefined) { if (videoRef.current?.paused) { @@ -283,18 +302,6 @@ export default function HlsVideoPlayer({ clearTimeout(bufferTimeout); setBufferTimeout(undefined); } - - setBufferTimeout( - setTimeout(() => { - if ( - document.visibilityState === "visible" && - videoRef.current && - !videoRef.current.paused - ) { - onError("stalled"); - } - }, 3000), - ); } }} onTimeUpdate={() =>