Skip to content

Commit eda2f17

Browse files
authored
Merge pull request #42157 from KMichel1030/fix/issue-40735
Playing video is not paused when opening attachment modal. #40735
2 parents 23878ac + 03b03d8 commit eda2f17

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/components/VideoPlayer/BaseVideoPlayer.tsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -223,22 +223,25 @@ function BaseVideoPlayer({
223223
return;
224224
}
225225

226-
// If we are uploading a new video, we want to immediately set the video player ref.
226+
// If we are uploading a new video, we want to pause previous playing video and immediately set the video player ref.
227+
if (currentVideoPlayerRef.current) {
228+
pauseVideo();
229+
}
227230
currentVideoPlayerRef.current = videoPlayerRef.current;
228-
}, [url, currentVideoPlayerRef, isUploading]);
231+
}, [url, currentVideoPlayerRef, isUploading, pauseVideo]);
229232

230233
const isCurrentlyURLSetRef = useRef<boolean>();
231234
isCurrentlyURLSetRef.current = isCurrentlyURLSet;
232235

233236
useEffect(
234237
() => () => {
235-
if (!isCurrentlyURLSetRef.current) {
238+
if (shouldUseSharedVideoElement || !isCurrentlyURLSetRef.current) {
236239
return;
237240
}
238241

239242
setCurrentlyPlayingURL(null);
240243
},
241-
[setCurrentlyPlayingURL],
244+
[setCurrentlyPlayingURL, shouldUseSharedVideoElement],
242245
);
243246
// update shared video elements
244247
useEffect(() => {

0 commit comments

Comments
 (0)