Skip to content

Commit

Permalink
Merge pull request #39479 from shahinyan11/issues/38307
Browse files Browse the repository at this point in the history
Fix an inconsistency between the mute status icon in full screen mode…
  • Loading branch information
thienlnam authored Apr 15, 2024
2 parents 334dcf8 + 461030b commit fdae0bd
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/components/VideoPlayer/BaseVideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Hoverable from '@components/Hoverable';
import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback';
import {useFullScreenContext} from '@components/VideoPlayerContexts/FullScreenContext';
import {usePlaybackContext} from '@components/VideoPlayerContexts/PlaybackContext';
import {useVolumeContext} from '@components/VideoPlayerContexts/VolumeContext';
import VideoPopoverMenu from '@components/VideoPopoverMenu';
import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -77,6 +78,7 @@ function BaseVideoPlayer({
const isCurrentlyURLSet = currentlyPlayingURL === url;
const isUploading = CONST.ATTACHMENT_LOCAL_URL_PREFIX.some((prefix) => url.startsWith(prefix));
const videoStateRef = useRef<AVPlaybackStatus | null>(null);
const {updateVolume} = useVolumeContext();

const togglePlayCurrentVideo = useCallback(() => {
videoResumeTryNumber.current = 0;
Expand Down Expand Up @@ -156,6 +158,16 @@ function BaseVideoPlayer({

if (event.fullscreenUpdate === VideoFullscreenUpdate.PLAYER_DID_DISMISS) {
isFullScreenRef.current = false;

// Sync volume updates in full screen mode after leaving it
currentVideoPlayerRef.current?.getStatusAsync?.().then((status) => {
if (!('isMuted' in status)) {
return;
}

updateVolume(status.isMuted ? 0 : status.volume || 1);
});

// we need to use video state ref to check if video is playing, to catch proper state after exiting fullscreen
// and also fix a bug with fullscreen mode dismissing when handleFullscreenUpdate function changes
if (videoStateRef.current && (!('isPlaying' in videoStateRef.current) || videoStateRef.current.isPlaying)) {
Expand All @@ -165,7 +177,7 @@ function BaseVideoPlayer({
}
}
},
[isFullScreenRef, onFullscreenUpdate, pauseVideo, playVideo, videoResumeTryNumber],
[isFullScreenRef, onFullscreenUpdate, pauseVideo, playVideo, videoResumeTryNumber, updateVolume, currentVideoPlayerRef],
);

const bindFunctions = useCallback(() => {
Expand Down

0 comments on commit fdae0bd

Please sign in to comment.