diff --git a/src/components/middle/message/RoundVideo.tsx b/src/components/middle/message/RoundVideo.tsx index 7c375307f..1dcde9c2b 100644 --- a/src/components/middle/message/RoundVideo.tsx +++ b/src/components/middle/message/RoundVideo.tsx @@ -38,17 +38,7 @@ type OwnProps = { isDownloading?: boolean; }; -let currentOnRelease: NoneToVoidFunction; - -function createCapture(onRelease: NoneToVoidFunction) { - return () => { - if (currentOnRelease) { - currentOnRelease(); - } - - currentOnRelease = onRelease; - }; -} +let stopPrevious: NoneToVoidFunction; const RoundVideo: FC = ({ message, @@ -130,17 +120,24 @@ const RoundVideo: FC = ({ const shouldPlay = Boolean(mediaData && isIntersecting); - const stopPlaying = () => { + const stopPlaying = useCallback(() => { + if (!playerRef.current) { + return; + } + setIsActivated(false); setProgress(0); - safePlay(playerRef.current!); + safePlay(playerRef.current); fastRaf(() => { playingProgressRef.current!.innerHTML = ''; }); - }; + }, []); - const capturePlaying = createCapture(stopPlaying); + const capturePlaying = useCallback(() => { + stopPrevious?.(); + stopPrevious = stopPlaying; + }, [stopPlaying]); useEffect(() => { if (!playerRef.current) {