From 9972b71b3636d82cc259f48cf9a2d3f7528b82aa Mon Sep 17 00:00:00 2001 From: dominictb Date: Mon, 5 Aug 2024 14:56:54 +0700 Subject: [PATCH 1/3] fix: update volume to 0.25 if unmute but volume is 0 --- src/components/VideoPlayer/BaseVideoPlayer.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/components/VideoPlayer/BaseVideoPlayer.tsx b/src/components/VideoPlayer/BaseVideoPlayer.tsx index 8c04830bed2fc..e3cc9e7885e5f 100644 --- a/src/components/VideoPlayer/BaseVideoPlayer.tsx +++ b/src/components/VideoPlayer/BaseVideoPlayer.tsx @@ -130,6 +130,9 @@ function BaseVideoPlayer({ [playVideo, videoResumeTryNumberRef], ); + const prevIsMuted = useRef(false); + const prevVolume = useRef(0); + const handlePlaybackStatusUpdate = useCallback( (status: AVPlaybackStatus) => { if (!status.isLoaded) { @@ -142,6 +145,13 @@ function BaseVideoPlayer({ onPlaybackStatusUpdate?.(status); return; } + + if (prevIsMuted.current && prevVolume.current === 0 && !status.isMuted) { + updateVolume(0.25); + } + prevIsMuted.current = status.isMuted; + prevVolume.current = status.volume; + const isVideoPlaying = status.isPlaying; // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const currentDuration = status.durationMillis || videoDuration * 1000; From da5edf870268aaefdb65bf192792716a9e05af3d Mon Sep 17 00:00:00 2001 From: dominictb Date: Wed, 7 Aug 2024 22:23:53 +0700 Subject: [PATCH 2/3] fix: manually set isMuted to true one volume is 0 in full screen mode --- src/components/VideoPlayer/BaseVideoPlayer.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/VideoPlayer/BaseVideoPlayer.tsx b/src/components/VideoPlayer/BaseVideoPlayer.tsx index e3cc9e7885e5f..2a7d6fa82abc5 100644 --- a/src/components/VideoPlayer/BaseVideoPlayer.tsx +++ b/src/components/VideoPlayer/BaseVideoPlayer.tsx @@ -149,6 +149,9 @@ function BaseVideoPlayer({ if (prevIsMuted.current && prevVolume.current === 0 && !status.isMuted) { updateVolume(0.25); } + if (isFullScreenRef.current && prevVolume.current !== 0 && status.volume === 0 && !status.isMuted) { + currentVideoPlayerRef.current?.setStatusAsync({isMuted: true}); + } prevIsMuted.current = status.isMuted; prevVolume.current = status.volume; From 44ff6092098d42814dceb56d64b503ce3e9efd6a Mon Sep 17 00:00:00 2001 From: dominictb Date: Thu, 8 Aug 2024 10:14:00 +0700 Subject: [PATCH 3/3] chore: fix react-compiler checks --- src/components/VideoPlayer/BaseVideoPlayer.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/VideoPlayer/BaseVideoPlayer.tsx b/src/components/VideoPlayer/BaseVideoPlayer.tsx index 2a7d6fa82abc5..91f02943680fc 100644 --- a/src/components/VideoPlayer/BaseVideoPlayer.tsx +++ b/src/components/VideoPlayer/BaseVideoPlayer.tsx @@ -130,8 +130,8 @@ function BaseVideoPlayer({ [playVideo, videoResumeTryNumberRef], ); - const prevIsMuted = useRef(false); - const prevVolume = useRef(0); + const prevIsMutedRef = useRef(false); + const prevVolumeRef = useRef(0); const handlePlaybackStatusUpdate = useCallback( (status: AVPlaybackStatus) => { @@ -146,14 +146,14 @@ function BaseVideoPlayer({ return; } - if (prevIsMuted.current && prevVolume.current === 0 && !status.isMuted) { + if (prevIsMutedRef.current && prevVolumeRef.current === 0 && !status.isMuted) { updateVolume(0.25); } - if (isFullScreenRef.current && prevVolume.current !== 0 && status.volume === 0 && !status.isMuted) { + if (isFullScreenRef.current && prevVolumeRef.current !== 0 && status.volume === 0 && !status.isMuted) { currentVideoPlayerRef.current?.setStatusAsync({isMuted: true}); } - prevIsMuted.current = status.isMuted; - prevVolume.current = status.volume; + prevIsMutedRef.current = status.isMuted; + prevVolumeRef.current = status.volume; const isVideoPlaying = status.isPlaying; // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing