diff --git a/src/components/Attachments/AttachmentView/index.tsx b/src/components/Attachments/AttachmentView/index.tsx index df6763859e07..c20c87b66717 100644 --- a/src/components/Attachments/AttachmentView/index.tsx +++ b/src/components/Attachments/AttachmentView/index.tsx @@ -125,7 +125,7 @@ function AttachmentView({ }: AttachmentViewProps) { const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(transactionID)}`, {canBeMissing: true}); const {translate} = useLocalize(); - const {updateCurrentURLAndReportID, playVideo} = usePlaybackContext(); + const {updateCurrentURLAndReportID, currentlyPlayingURL, playVideo} = usePlaybackContext(); const attachmentCarouselPagerContext = useContext(AttachmentCarouselPagerContext); const {onAttachmentError} = attachmentCarouselPagerContext ?? {}; @@ -144,11 +144,12 @@ function AttachmentView({ if (!isFocused && !isInFocusedModal && !(file && isUsedInAttachmentModal)) { return; } - updateCurrentURLAndReportID(isVideo && typeof source === 'string' ? source : undefined, reportID); - if (isVideo && typeof source === 'string') { + const videoSource = isVideo && typeof source === 'string' ? source : undefined; + updateCurrentURLAndReportID(videoSource, reportID); + if (videoSource && currentlyPlayingURL === videoSource) { playVideo(); } - }, [file, isFocused, isInFocusedModal, isUsedInAttachmentModal, isVideo, reportID, source, updateCurrentURLAndReportID, playVideo]); + }, [file, isFocused, isInFocusedModal, isUsedInAttachmentModal, isVideo, reportID, source, updateCurrentURLAndReportID, playVideo, currentlyPlayingURL]); const [imageError, setImageError] = useState(false); diff --git a/src/components/VideoPlayerContexts/PlaybackContext/index.tsx b/src/components/VideoPlayerContexts/PlaybackContext/index.tsx index 78861142b6c9..0ce29dda869e 100644 --- a/src/components/VideoPlayerContexts/PlaybackContext/index.tsx +++ b/src/components/VideoPlayerContexts/PlaybackContext/index.tsx @@ -33,7 +33,7 @@ function PlaybackContextProvider({children}: ChildrenProps) { if (!url) { if (currentlyPlayingURL) { - video.stop(); + video.pause(); } return; }