Fixed bug where the video hangs after initial playback

canary
WolverinDEV 2020-12-03 01:30:55 +01:00
parent abf5d6a52a
commit a572493d57
1 changed files with 16 additions and 1 deletions

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 refVideo = useRef<HTMLVideoElement>();
const refReplayTimeout = useRef<number>();
useEffect(() => {
const video = refVideo.current;
@ -86,10 +87,24 @@ const VideoStreamReplay = React.memo((props: { stream: MediaStream | undefined,
video.srcObject = props.stream;
video.autoplay = 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 {
video.style.opacity = "0";
}
return () => {
clearInterval(refReplayTimeout.current);
refReplayTimeout.current = undefined;
}
}, [ props.stream ]);
return (