diff --git a/src/components/Attachments/AttachmentView/index.js b/src/components/Attachments/AttachmentView/index.js index 6da7be841537..c871628f65e7 100755 --- a/src/components/Attachments/AttachmentView/index.js +++ b/src/components/Attachments/AttachmentView/index.js @@ -100,14 +100,14 @@ function AttachmentView({ const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); const [loadComplete, setLoadComplete] = useState(false); - const isVideo = typeof source === 'string' && Str.isVideo(source); + const isVideo = (typeof source === 'string' && Str.isVideo(source)) || (file && Str.isVideo(file.name)); useEffect(() => { - if (!isFocused) { + if (!isFocused && !(file && isUsedInAttachmentModal)) { return; } updateCurrentlyPlayingURL(isVideo ? source : null); - }, [isFocused, isVideo, source, updateCurrentlyPlayingURL]); + }, [isFocused, isVideo, source, updateCurrentlyPlayingURL, file, isUsedInAttachmentModal]); const [imageError, setImageError] = useState(false); @@ -201,7 +201,7 @@ function AttachmentView({ ); } - if (isVideo || (file && Str.isVideo(file.name))) { + if (isVideo) { return ( url.startsWith(prefix)); const togglePlayCurrentVideo = useCallback(() => { videoResumeTryNumber.current = 0; @@ -144,8 +147,8 @@ function BaseVideoPlayer({ if (shouldUseSharedVideoElement || url !== currentlyPlayingURL) { return; } - shareVideoPlayerElements(videoPlayerRef.current, videoPlayerElementParentRef.current, videoPlayerElementRef.current); - }, [currentlyPlayingURL, shouldUseSharedVideoElement, shareVideoPlayerElements, updateSharedElements, url]); + shareVideoPlayerElements(videoPlayerRef.current, videoPlayerElementParentRef.current, videoPlayerElementRef.current, isUploading); + }, [currentlyPlayingURL, shouldUseSharedVideoElement, shareVideoPlayerElements, updateSharedElements, url, isUploading]); // append shared video element to new parent (used for example in attachment modal) useEffect(() => { diff --git a/src/components/VideoPlayer/shouldReplayVideo.android.ts b/src/components/VideoPlayer/shouldReplayVideo.android.ts index c1c3de034aac..2fae779deae2 100644 --- a/src/components/VideoPlayer/shouldReplayVideo.android.ts +++ b/src/components/VideoPlayer/shouldReplayVideo.android.ts @@ -4,7 +4,9 @@ import type {AVPlaybackStatusSuccess} from 'expo-av'; * Whether to replay the video when users press play button */ export default function shouldReplayVideo(e: AVPlaybackStatusSuccess, isPlaying: boolean, duration: number, position: number): boolean { - if (!isPlaying && !e.didJustFinish && duration === position) { + // When we upload an attachment on Android, didJustFinish is false and the duration is 0 + // so we should return false if the duration is 0 to prevent auto-playing video when the video is uploading + if (!isPlaying && !e.didJustFinish && duration === position && duration !== 0) { return true; } return false; diff --git a/src/components/VideoPlayerContexts/PlaybackContext.js b/src/components/VideoPlayerContexts/PlaybackContext.js index 8cf09f81c614..e96daa20bce7 100644 --- a/src/components/VideoPlayerContexts/PlaybackContext.js +++ b/src/components/VideoPlayerContexts/PlaybackContext.js @@ -56,11 +56,14 @@ function PlaybackContextProvider({children}) { ); const shareVideoPlayerElements = useCallback( - (ref, parent, child) => { + (ref, parent, child, isUploading) => { currentVideoPlayerRef.current = ref; setOriginalParent(parent); setSharedElement(child); - playVideo(); + // Prevents autoplay when uploading the attachment + if (!isUploading) { + playVideo(); + } }, [playVideo], );