From 036e83b5b52516e64640f0ba7a3a4fb2e977d6f2 Mon Sep 17 00:00:00 2001 From: R-J Lim Date: Mon, 19 Feb 2024 10:45:56 +0900 Subject: [PATCH] Fix clock inconsistency when changing language --- common/app/components/VideoPlayer.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/common/app/components/VideoPlayer.tsx b/common/app/components/VideoPlayer.tsx index e13d2623..868c515d 100755 --- a/common/app/components/VideoPlayer.tsx +++ b/common/app/components/VideoPlayer.tsx @@ -394,6 +394,9 @@ export default function VideoPlayer({ forceRender({}); }, [playerChannel]); + const onErrorRef = useRef(onError); + onErrorRef.current = onError; + const videoRefCallback = useCallback( (element: HTMLVideoElement) => { if (element) { @@ -417,14 +420,14 @@ export default function VideoPlayer({ }; videoElement.ontimeupdate = (event) => clock.setTime(element.currentTime * 1000); - videoElement.onerror = (event) => onError(errorMessage(element)); + videoElement.onerror = (event) => onErrorRef.current?.(errorMessage(element)); videoElement.onplay = updatePlayerState; videoElement.onpause = updatePlayerState; videoElement.onratechange = updatePlayerState; videoElement.onseeked = updatePlayerState; } }, - [clock, playerChannel, updatePlayerState, onError] + [clock, playerChannel, updatePlayerState] ); function selectAudioTrack(id: string) {