Round Video: Some fixes (#1041)

This commit is contained in:
Alexander Zinchuk 2021-04-22 12:09:12 +03:00
parent 4e8381f997
commit 4df0f08365
2 changed files with 33 additions and 12 deletions

View File

@ -35,4 +35,10 @@
stroke-opacity: .35;
stroke-linecap: round;
}
video::-internal-media-controls-cast-button,
video::-webkit-media-controls,
video::-webkit-media-controls-start-playback-button {
display: none;
}
}

View File

@ -35,6 +35,18 @@ type OwnProps = {
lastSyncTime?: number;
};
let currentOnRelease: NoneToVoidFunction;
function createCapture(onRelease: NoneToVoidFunction) {
return () => {
if (currentOnRelease) {
currentOnRelease();
}
currentOnRelease = onRelease;
};
}
const RoundVideo: FC<OwnProps> = ({
message,
observeIntersection,
@ -103,6 +115,18 @@ const RoundVideo: FC<OwnProps> = ({
const shouldPlay = Boolean(mediaData && isIntersecting);
const stopPlaying = () => {
setIsActivated(false);
setProgress(0);
safePlay(playerRef.current!);
requestAnimationFrame(() => {
playingProgressRef.current!.innerHTML = '';
});
};
const capturePlaying = createCapture(stopPlaying);
useEffect(() => {
if (!playerRef.current) {
return;
@ -136,8 +160,9 @@ const RoundVideo: FC<OwnProps> = ({
} else {
playerEl.currentTime = 0;
setIsActivated(true);
capturePlaying();
}
}, [isActivated, mediaData]);
}, [capturePlaying, isActivated, mediaData]);
const handleTimeUpdate = useCallback((e: React.UIEvent<HTMLVideoElement>) => {
const playerEl = e.currentTarget;
@ -145,16 +170,6 @@ const RoundVideo: FC<OwnProps> = ({
setProgress(playerEl.currentTime / playerEl.duration);
}, []);
const handleEnded = useCallback(() => {
setIsActivated(false);
setProgress(0);
safePlay(playerRef.current!);
requestAnimationFrame(() => {
playingProgressRef.current!.innerHTML = '';
});
}, []);
const videoClassName = buildClassName('full-media', transitionClassNames);
return (
@ -187,7 +202,7 @@ const RoundVideo: FC<OwnProps> = ({
loop={!isActivated}
playsInline
poster={thumbDataUri}
onEnded={isActivated ? handleEnded : undefined}
onEnded={isActivated ? stopPlaying : undefined}
// eslint-disable-next-line react/jsx-props-no-spreading
{...bufferingHandlers}
onTimeUpdate={isActivated ? handleTimeUpdate : undefined}