Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect video downloaded #40647 #41054

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions 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 {useVideoPopoverMenuContext} from '@components/VideoPlayerContexts/VideoPopoverMenuContext';
import {useVolumeContext} from '@components/VideoPlayerContexts/VolumeContext';
import VideoPopoverMenu from '@components/VideoPopoverMenu';
import useNetwork from '@hooks/useNetwork';
Expand Down Expand Up @@ -79,6 +80,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 togglePlayCurrentVideo = useCallback(() => {
videoResumeTryNumber.current = 0;
Expand All @@ -93,6 +95,7 @@ function BaseVideoPlayer({

const showPopoverMenu = (event?: GestureResponderEvent | KeyboardEvent) => {
setIsPopoverVisible(true);
videoPopoverMenuPlayerRef.current = videoPlayerRef.current;
if (!event || !('nativeEvent' in event)) {
return;
}
Expand Down
13 changes: 8 additions & 5 deletions src/components/VideoPlayerContexts/VideoPopoverMenuContext.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, {useCallback, useContext, useMemo, useState} from 'react';
import type {AVPlaybackSourceObject} from 'expo-av';
import React, {useCallback, useContext, useMemo, useRef, useState} from 'react';
import * as Expensicons from '@components/Icon/Expensicons';
import type {PopoverMenuItem} from '@components/PopoverMenu';
import type {VideoWithOnFullScreenUpdate} from '@components/VideoPlayer/types';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL';
Expand All @@ -18,6 +20,7 @@ function VideoPopoverMenuContextProvider({children}: ChildrenProps) {
const [currentPlaybackSpeed, setCurrentPlaybackSpeed] = useState<PlaybackSpeed>(CONST.VIDEO_PLAYER.PLAYBACK_SPEEDS[2]);
const {isOffline} = useNetwork();
const isLocalFile = currentlyPlayingURL && CONST.ATTACHMENT_LOCAL_URL_PREFIX.some((prefix) => currentlyPlayingURL.startsWith(prefix));
const videoPopoverMenuPlayerRef = useRef<VideoWithOnFullScreenUpdate | null>(null);

const updatePlaybackSpeed = useCallback(
(speed: PlaybackSpeed) => {
Expand All @@ -28,12 +31,12 @@ function VideoPopoverMenuContextProvider({children}: ChildrenProps) {
);

const downloadAttachment = useCallback(() => {
if (currentlyPlayingURL === null) {
if (videoPopoverMenuPlayerRef.current === null) {
return;
}
const sourceURI = addEncryptedAuthTokenToURL(currentlyPlayingURL);
const sourceURI = addEncryptedAuthTokenToURL((videoPopoverMenuPlayerRef.current.props.source as AVPlaybackSourceObject).uri);
fileDownload(sourceURI);
blimpich marked this conversation as resolved.
Show resolved Hide resolved
}, [currentlyPlayingURL]);
}, [videoPopoverMenuPlayerRef]);

const menuItems = useMemo(() => {
const items: PopoverMenuItem[] = [];
Expand Down Expand Up @@ -63,7 +66,7 @@ function VideoPopoverMenuContextProvider({children}: ChildrenProps) {
return items;
}, [currentPlaybackSpeed, downloadAttachment, translate, updatePlaybackSpeed, isOffline, isLocalFile]);

const contextValue = useMemo(() => ({menuItems, updatePlaybackSpeed}), [menuItems, updatePlaybackSpeed]);
const contextValue = useMemo(() => ({menuItems, videoPopoverMenuPlayerRef, updatePlaybackSpeed}), [menuItems, videoPopoverMenuPlayerRef, updatePlaybackSpeed]);
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 @@ -28,6 +28,7 @@ type VolumeContext = {

type VideoPopoverMenuContext = {
menuItems: PopoverMenuItem[];
videoPopoverMenuPlayerRef: MutableRefObject<VideoWithOnFullScreenUpdate | null>;
updatePlaybackSpeed: (speed: PlaybackSpeed) => void;
};

Expand Down
Loading