From 2497488eec8ff9c51e5a3c184052ec8171ec90b5 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Mon, 19 Jul 2021 01:56:30 +0300 Subject: [PATCH] Round Video: Fix pause after first click on Safari (#1291) --- src/components/middle/message/RoundVideo.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/middle/message/RoundVideo.tsx b/src/components/middle/message/RoundVideo.tsx index 1172daa2..2216c7a5 100644 --- a/src/components/middle/message/RoundVideo.tsx +++ b/src/components/middle/message/RoundVideo.tsx @@ -23,6 +23,7 @@ import useVideoCleanup from '../../../hooks/useVideoCleanup'; import usePauseOnInactive from './hooks/usePauseOnInactive'; import useBlurredMediaThumbRef from './hooks/useBlurredMediaThumbRef'; import safePlay from '../../../util/safePlay'; +import { fastRaf } from '../../../util/schedulers'; import ProgressSpinner from '../../ui/ProgressSpinner'; @@ -121,7 +122,7 @@ const RoundVideo: FC = ({ setProgress(0); safePlay(playerRef.current!); - requestAnimationFrame(() => { + fastRaf(() => { playingProgressRef.current!.innerHTML = ''; }); }; @@ -162,7 +163,11 @@ const RoundVideo: FC = ({ } } else { capturePlaying(); + // Pause is a workaround for iOS Safari – otherwise it stops video after several frames + playerEl.pause(); playerEl.currentTime = 0; + safePlay(playerEl); + setIsActivated(true); } }, [capturePlaying, isActivated, mediaData]);