Fixed bug where the video hangs after initial playback

This commit is contained in:
WolverinDEV 2020-12-03 01:30:55 +01:00
parent abf5d6a52a
commit a572493d57

View file

@ -78,6 +78,7 @@ const VideoInfo = React.memo((props: { videoId: string }) => {
const VideoStreamReplay = React.memo((props: { stream: MediaStream | undefined, className: string, title: string }) => { const VideoStreamReplay = React.memo((props: { stream: MediaStream | undefined, className: string, title: string }) => {
const refVideo = useRef<HTMLVideoElement>(); const refVideo = useRef<HTMLVideoElement>();
const refReplayTimeout = useRef<number>();
useEffect(() => { useEffect(() => {
const video = refVideo.current; const video = refVideo.current;
@ -86,10 +87,24 @@ const VideoStreamReplay = React.memo((props: { stream: MediaStream | undefined,
video.srcObject = props.stream; video.srcObject = props.stream;
video.autoplay = true; video.autoplay = true;
video.muted = true; video.muted = true;
video.play().then(undefined).catch(undefined);
video.play().then(undefined).catch(() => {
logWarn(LogCategory.VIDEO, tr("Failed to start video replay. Retrying in 500ms intervals."));
refReplayTimeout.current = setInterval(() => {
video.play().then(() => {
clearInterval(refReplayTimeout.current);
refReplayTimeout.current = undefined;
}).catch(() => {});
});
});
} else { } else {
video.style.opacity = "0"; video.style.opacity = "0";
} }
return () => {
clearInterval(refReplayTimeout.current);
refReplayTimeout.current = undefined;
}
}, [ props.stream ]); }, [ props.stream ]);
return ( return (