From a637a2d9c15bf3f2a48e724d90023fb24c3e8922 Mon Sep 17 00:00:00 2001 From: Akmal Isomadinov Date: Fri, 24 Mar 2023 23:09:49 +0500 Subject: [PATCH] Web:Common:Components:MediaViewer:Sub-Components:ViewerPlayer Refactoring viewerPlayer --- .../sub-components/ViewerPlayer/index.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/common/components/MediaViewer/sub-components/ViewerPlayer/index.tsx b/packages/common/components/MediaViewer/sub-components/ViewerPlayer/index.tsx index f4b5607142..3e64905458 100644 --- a/packages/common/components/MediaViewer/sub-components/ViewerPlayer/index.tsx +++ b/packages/common/components/MediaViewer/sub-components/ViewerPlayer/index.tsx @@ -68,6 +68,8 @@ function ViewerPlayer({ const containerRef = useRef(null); const playerWrapperRef = useRef(null); + const isDurationInfinityRef = useRef(false); + const [isLoading, setIsLoading] = useState(false); const [isPlaying, setIsPlaying] = useState(false); const [isWaiting, setIsWaiting] = useState(false); @@ -323,7 +325,7 @@ function ViewerPlayer({ }); }; - const handleResize = (event: any) => { + const handleResize = () => { const target = videoRef.current; if (!target || isLoading) return; @@ -343,18 +345,24 @@ function ViewerPlayer({ target.playbackRate = 1; if (target.duration === Infinity) { + isDurationInfinityRef.current = true; target.currentTime = Number.MAX_SAFE_INTEGER; + return; } + setDuration(target.duration); + setIsLoading(false); }; const handleDurationChange = ( event: React.SyntheticEvent ) => { const target = event.target as HTMLVideoElement; - if (!Number.isFinite(target.duration)) return; + if (!Number.isFinite(target.duration) || !isDurationInfinityRef.current) + return; - setDuration(target.duration); target.currentTime = 0; + isDurationInfinityRef.current = false; + setDuration(target.duration); setIsLoading(false); };