Set src directly when HLS not supported

This commit is contained in:
2023-07-04 19:02:19 +01:00
parent 6e90e79ad9
commit cf19bb2f1e

View File

@ -13,14 +13,15 @@ export function LiveVideoPlayer(
const video = useRef<HTMLVideoElement>(null); const video = useRef<HTMLVideoElement>(null);
const streamCached = useMemo(() => props.stream, [props.stream]); const streamCached = useMemo(() => props.stream, [props.stream]);
const [status, setStatus] = useState<VideoStatus>(); const [status, setStatus] = useState<VideoStatus>();
const [src, setSrc] = useState(props.src);
useEffect(() => { useEffect(() => {
if ( if (
streamCached && streamCached &&
video.current && video.current &&
!video.current.src && !video.current.src
Hls.isSupported()
) { ) {
if (Hls.isSupported()) {
try { try {
const hls = new Hls(); const hls = new Hls();
hls.loadSource(streamCached); hls.loadSource(streamCached);
@ -42,14 +43,24 @@ export function LiveVideoPlayer(
console.error(e); console.error(e);
setStatus(VideoStatus.Offline); setStatus(VideoStatus.Offline);
} }
} else {
setSrc(streamCached);
setStatus(VideoStatus.Online);
video.current.muted = true;
video.current.load();
}
} }
}, [video, streamCached]); }, [video, streamCached]);
return ( return (
<> <>
<div className={status}> <div className={status}>
<div>{status}</div> <div>{status}</div>
</div> </div>
<video ref={video} {...props} controls={status === VideoStatus.Online} /> <video ref={video} {...{
...props,
stream: undefined
}} src={src} controls={status === VideoStatus.Online} />
</> </>
); );
} }