Round Video: Some fixes (#1041)
This commit is contained in:
parent
4e8381f997
commit
4df0f08365
@ -35,4 +35,10 @@
|
|||||||
stroke-opacity: .35;
|
stroke-opacity: .35;
|
||||||
stroke-linecap: round;
|
stroke-linecap: round;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
video::-internal-media-controls-cast-button,
|
||||||
|
video::-webkit-media-controls,
|
||||||
|
video::-webkit-media-controls-start-playback-button {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,6 +35,18 @@ type OwnProps = {
|
|||||||
lastSyncTime?: number;
|
lastSyncTime?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let currentOnRelease: NoneToVoidFunction;
|
||||||
|
|
||||||
|
function createCapture(onRelease: NoneToVoidFunction) {
|
||||||
|
return () => {
|
||||||
|
if (currentOnRelease) {
|
||||||
|
currentOnRelease();
|
||||||
|
}
|
||||||
|
|
||||||
|
currentOnRelease = onRelease;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const RoundVideo: FC<OwnProps> = ({
|
const RoundVideo: FC<OwnProps> = ({
|
||||||
message,
|
message,
|
||||||
observeIntersection,
|
observeIntersection,
|
||||||
@ -103,6 +115,18 @@ const RoundVideo: FC<OwnProps> = ({
|
|||||||
|
|
||||||
const shouldPlay = Boolean(mediaData && isIntersecting);
|
const shouldPlay = Boolean(mediaData && isIntersecting);
|
||||||
|
|
||||||
|
const stopPlaying = () => {
|
||||||
|
setIsActivated(false);
|
||||||
|
setProgress(0);
|
||||||
|
safePlay(playerRef.current!);
|
||||||
|
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
playingProgressRef.current!.innerHTML = '';
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const capturePlaying = createCapture(stopPlaying);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!playerRef.current) {
|
if (!playerRef.current) {
|
||||||
return;
|
return;
|
||||||
@ -136,8 +160,9 @@ const RoundVideo: FC<OwnProps> = ({
|
|||||||
} else {
|
} else {
|
||||||
playerEl.currentTime = 0;
|
playerEl.currentTime = 0;
|
||||||
setIsActivated(true);
|
setIsActivated(true);
|
||||||
|
capturePlaying();
|
||||||
}
|
}
|
||||||
}, [isActivated, mediaData]);
|
}, [capturePlaying, isActivated, mediaData]);
|
||||||
|
|
||||||
const handleTimeUpdate = useCallback((e: React.UIEvent<HTMLVideoElement>) => {
|
const handleTimeUpdate = useCallback((e: React.UIEvent<HTMLVideoElement>) => {
|
||||||
const playerEl = e.currentTarget;
|
const playerEl = e.currentTarget;
|
||||||
@ -145,16 +170,6 @@ const RoundVideo: FC<OwnProps> = ({
|
|||||||
setProgress(playerEl.currentTime / playerEl.duration);
|
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);
|
const videoClassName = buildClassName('full-media', transitionClassNames);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -187,7 +202,7 @@ const RoundVideo: FC<OwnProps> = ({
|
|||||||
loop={!isActivated}
|
loop={!isActivated}
|
||||||
playsInline
|
playsInline
|
||||||
poster={thumbDataUri}
|
poster={thumbDataUri}
|
||||||
onEnded={isActivated ? handleEnded : undefined}
|
onEnded={isActivated ? stopPlaying : undefined}
|
||||||
// eslint-disable-next-line react/jsx-props-no-spreading
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
||||||
{...bufferingHandlers}
|
{...bufferingHandlers}
|
||||||
onTimeUpdate={isActivated ? handleTimeUpdate : undefined}
|
onTimeUpdate={isActivated ? handleTimeUpdate : undefined}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user