Skip to content

Commit

Permalink
Merge pull request #41055 from KMichel1030/fix/issue-40646
Browse files Browse the repository at this point in the history
  • Loading branch information
blimpich authored May 15, 2024
2 parents b8b4e98 + 50e16d1 commit b826235
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src/components/VideoPlayer/BaseVideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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 type {PlaybackSpeed} from '@components/VideoPlayerContexts/types';
import {useVideoPopoverMenuContext} from '@components/VideoPlayerContexts/VideoPopoverMenuContext';
import {useVolumeContext} from '@components/VideoPlayerContexts/VolumeContext';
import VideoPopoverMenu from '@components/VideoPopoverMenu';
Expand Down Expand Up @@ -82,7 +83,7 @@ function BaseVideoPlayer({
const isUploading = CONST.ATTACHMENT_LOCAL_URL_PREFIX.some((prefix) => url.startsWith(prefix));
const videoStateRef = useRef<AVPlaybackStatus | null>(null);
const {updateVolume} = useVolumeContext();
const {videoPopoverMenuPlayerRef} = useVideoPopoverMenuContext();
const {videoPopoverMenuPlayerRef, setCurrentPlaybackSpeed} = useVideoPopoverMenuContext();

const togglePlayCurrentVideo = useCallback(() => {
videoResumeTryNumber.current = 0;
Expand All @@ -96,8 +97,14 @@ function BaseVideoPlayer({
}, [isCurrentlyURLSet, isPlaying, pauseVideo, playVideo, updateCurrentlyPlayingURL, url, videoResumeTryNumber]);

const showPopoverMenu = (event?: GestureResponderEvent | KeyboardEvent) => {
setIsPopoverVisible(true);
videoPopoverMenuPlayerRef.current = videoPlayerRef.current;
videoPlayerRef.current?.getStatusAsync().then((status) => {
if (!('rate' in status && status.rate)) {
return;
}
setIsPopoverVisible(true);
setCurrentPlaybackSpeed(status.rate as PlaybackSpeed);
});
if (!event || !('nativeEvent' in event)) {
return;
}
Expand Down
11 changes: 7 additions & 4 deletions src/components/VideoPlayerContexts/VideoPopoverMenuContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {PlaybackSpeed, VideoPopoverMenuContext} from './types';
const Context = React.createContext<VideoPopoverMenuContext | null>(null);

function VideoPopoverMenuContextProvider({children}: ChildrenProps) {
const {currentVideoPlayerRef, currentlyPlayingURL} = usePlaybackContext();
const {currentlyPlayingURL} = usePlaybackContext();
const {translate} = useLocalize();
const [currentPlaybackSpeed, setCurrentPlaybackSpeed] = useState<PlaybackSpeed>(CONST.VIDEO_PLAYER.PLAYBACK_SPEEDS[2]);
const {isOffline} = useNetwork();
Expand All @@ -24,9 +24,9 @@ function VideoPopoverMenuContextProvider({children}: ChildrenProps) {
const updatePlaybackSpeed = useCallback(
(speed: PlaybackSpeed) => {
setCurrentPlaybackSpeed(speed);
currentVideoPlayerRef.current?.setStatusAsync?.({rate: speed});
videoPopoverMenuPlayerRef.current?.setStatusAsync?.({rate: speed});
},
[currentVideoPlayerRef],
[videoPopoverMenuPlayerRef],
);

const downloadAttachment = useCallback(() => {
Expand Down Expand Up @@ -69,7 +69,10 @@ function VideoPopoverMenuContextProvider({children}: ChildrenProps) {
return items;
}, [currentPlaybackSpeed, downloadAttachment, translate, updatePlaybackSpeed, isOffline, isLocalFile]);

const contextValue = useMemo(() => ({menuItems, videoPopoverMenuPlayerRef, updatePlaybackSpeed}), [menuItems, videoPopoverMenuPlayerRef, updatePlaybackSpeed]);
const contextValue = useMemo(
() => ({menuItems, videoPopoverMenuPlayerRef, updatePlaybackSpeed, setCurrentPlaybackSpeed}),
[menuItems, videoPopoverMenuPlayerRef, updatePlaybackSpeed, setCurrentPlaybackSpeed],
);
return <Context.Provider value={contextValue}>{children}</Context.Provider>;
}

Expand Down
1 change: 1 addition & 0 deletions src/components/VideoPlayerContexts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type VideoPopoverMenuContext = {
menuItems: PopoverMenuItem[];
videoPopoverMenuPlayerRef: MutableRefObject<VideoWithOnFullScreenUpdate | null>;
updatePlaybackSpeed: (speed: PlaybackSpeed) => void;
setCurrentPlaybackSpeed: (speed: PlaybackSpeed) => void;
};

type FullScreenContext = {
Expand Down

0 comments on commit b826235

Please sign in to comment.