From 0dad1e2cad8861956d684e3b39ddd2727b3a16e3 Mon Sep 17 00:00:00 2001 From: Shahe Shahinyan Date: Fri, 23 Feb 2024 10:58:05 +0400 Subject: [PATCH 1/5] FIx downloading video crash --- src/components/VideoPlayer/BaseVideoPlayer.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/VideoPlayer/BaseVideoPlayer.js b/src/components/VideoPlayer/BaseVideoPlayer.js index df79c7ef18da..1bf77768c8e3 100644 --- a/src/components/VideoPlayer/BaseVideoPlayer.js +++ b/src/components/VideoPlayer/BaseVideoPlayer.js @@ -139,6 +139,10 @@ function BaseVideoPlayer({ }); }, [currentVideoPlayerRef, handleFullscreenUpdate, handlePlaybackStatusUpdate]); + useEffect(() => { + currentVideoPlayerRef.current = videoPlayerRef.current; + }, [url]); + // update shared video elements useEffect(() => { if (shouldUseSharedVideoElement || url !== currentlyPlayingURL) { From 1f7644233b68bda729c8b96c0e92ad9a14adcd6f Mon Sep 17 00:00:00 2001 From: Shahe Shahinyan Date: Fri, 23 Feb 2024 17:07:10 +0400 Subject: [PATCH 2/5] Fix lint error --- src/components/VideoPlayer/BaseVideoPlayer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/VideoPlayer/BaseVideoPlayer.js b/src/components/VideoPlayer/BaseVideoPlayer.js index 1bf77768c8e3..ba6dac66a1c3 100644 --- a/src/components/VideoPlayer/BaseVideoPlayer.js +++ b/src/components/VideoPlayer/BaseVideoPlayer.js @@ -141,7 +141,7 @@ function BaseVideoPlayer({ useEffect(() => { currentVideoPlayerRef.current = videoPlayerRef.current; - }, [url]); + }, [url, currentVideoPlayerRef]); // update shared video elements useEffect(() => { From 84e44aaf78a2160be5b6da4dba3c4937ee1da5aa Mon Sep 17 00:00:00 2001 From: Shahe Shahinyan Date: Wed, 28 Feb 2024 13:25:09 +0400 Subject: [PATCH 3/5] Hide download button for local files --- .../VideoPlayerContexts/VideoPopoverMenuContext.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/VideoPlayerContexts/VideoPopoverMenuContext.js b/src/components/VideoPlayerContexts/VideoPopoverMenuContext.js index 4bb10e526fe4..7b51cb0e2c2d 100644 --- a/src/components/VideoPlayerContexts/VideoPopoverMenuContext.js +++ b/src/components/VideoPlayerContexts/VideoPopoverMenuContext.js @@ -16,6 +16,7 @@ function VideoPopoverMenuContextProvider({children}) { const {translate} = useLocalize(); const [currentPlaybackSpeed, setCurrentPlaybackSpeed] = useState(CONST.VIDEO_PLAYER.PLAYBACK_SPEEDS[2]); const {isOffline} = useNetwork(); + const isLocalFile = currentlyPlayingURL && (currentlyPlayingURL.startsWith('blob:') || currentlyPlayingURL.startsWith('file:')); const updatePlaybackSpeed = useCallback( (speed) => { @@ -26,14 +27,14 @@ function VideoPopoverMenuContextProvider({children}) { ); const downloadAttachment = useCallback(() => { - const sourceURI = currentlyPlayingURL.startsWith('blob:') || currentlyPlayingURL.startsWith('file:') ? currentlyPlayingURL : addEncryptedAuthTokenToURL(currentlyPlayingURL); + const sourceURI = isLocalFile ? currentlyPlayingURL : addEncryptedAuthTokenToURL(currentlyPlayingURL); fileDownload(sourceURI); }, [currentlyPlayingURL]); const menuItems = useMemo(() => { const items = []; - if (!isOffline) { + if (!isOffline && !isLocalFile) { items.push({ icon: Expensicons.Download, text: translate('common.download'), From 21765c18b16b39e25904bd7308c993a5bf0f1708 Mon Sep 17 00:00:00 2001 From: Shahe Shahinyan Date: Wed, 28 Feb 2024 13:56:40 +0400 Subject: [PATCH 4/5] Fix lint error --- src/components/VideoPlayerContexts/VideoPopoverMenuContext.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/VideoPlayerContexts/VideoPopoverMenuContext.js b/src/components/VideoPlayerContexts/VideoPopoverMenuContext.js index 7b51cb0e2c2d..334261c43d22 100644 --- a/src/components/VideoPlayerContexts/VideoPopoverMenuContext.js +++ b/src/components/VideoPlayerContexts/VideoPopoverMenuContext.js @@ -29,7 +29,7 @@ function VideoPopoverMenuContextProvider({children}) { const downloadAttachment = useCallback(() => { const sourceURI = isLocalFile ? currentlyPlayingURL : addEncryptedAuthTokenToURL(currentlyPlayingURL); fileDownload(sourceURI); - }, [currentlyPlayingURL]); + }, [currentlyPlayingURL, isLocalFile]); const menuItems = useMemo(() => { const items = []; From f7852ad614f4fe0651b3fe56449bdb31537d5a39 Mon Sep 17 00:00:00 2001 From: Shahe Shahinyan Date: Thu, 29 Feb 2024 11:24:54 +0400 Subject: [PATCH 5/5] Addressed to reviewer comments --- .../VideoPlayerContexts/VideoPopoverMenuContext.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/VideoPlayerContexts/VideoPopoverMenuContext.js b/src/components/VideoPlayerContexts/VideoPopoverMenuContext.js index 334261c43d22..4a5c15080c98 100644 --- a/src/components/VideoPlayerContexts/VideoPopoverMenuContext.js +++ b/src/components/VideoPlayerContexts/VideoPopoverMenuContext.js @@ -16,7 +16,7 @@ function VideoPopoverMenuContextProvider({children}) { const {translate} = useLocalize(); const [currentPlaybackSpeed, setCurrentPlaybackSpeed] = useState(CONST.VIDEO_PLAYER.PLAYBACK_SPEEDS[2]); const {isOffline} = useNetwork(); - const isLocalFile = currentlyPlayingURL && (currentlyPlayingURL.startsWith('blob:') || currentlyPlayingURL.startsWith('file:')); + const isLocalFile = currentlyPlayingURL && _.some(CONST.ATTACHMENT_LOCAL_URL_PREFIX, (prefix) => currentlyPlayingURL.startsWith(prefix)); const updatePlaybackSpeed = useCallback( (speed) => { @@ -27,9 +27,9 @@ function VideoPopoverMenuContextProvider({children}) { ); const downloadAttachment = useCallback(() => { - const sourceURI = isLocalFile ? currentlyPlayingURL : addEncryptedAuthTokenToURL(currentlyPlayingURL); + const sourceURI = addEncryptedAuthTokenToURL(currentlyPlayingURL); fileDownload(sourceURI); - }, [currentlyPlayingURL, isLocalFile]); + }, [currentlyPlayingURL]); const menuItems = useMemo(() => { const items = []; @@ -60,7 +60,7 @@ function VideoPopoverMenuContextProvider({children}) { }); return items; - }, [currentPlaybackSpeed, downloadAttachment, translate, updatePlaybackSpeed, isOffline]); + }, [currentPlaybackSpeed, downloadAttachment, translate, updatePlaybackSpeed, isOffline, isLocalFile]); const contextValue = useMemo(() => ({menuItems, updatePlaybackSpeed}), [menuItems, updatePlaybackSpeed]); return {children};