This commit is contained in:
2023-06-22 15:16:14 +01:00
parent 0ad5e387a1
commit 6a0ee5362a
16 changed files with 342 additions and 24 deletions

View File

@ -1,16 +1,18 @@
import Hls from "hls.js";
import { HTMLProps, useEffect, useRef } from "react";
import { HTMLProps, useEffect, useMemo, useRef } from "react";
export function LiveVideoPlayer(props: HTMLProps<HTMLVideoElement> & { stream?: string }) {
const video = useRef<HTMLVideoElement>(null);
const streamCached = useMemo(() => props.stream, [props.stream]);
useEffect(() => {
if (props.stream && video.current && !video.current.src && Hls.isSupported()) {
if (streamCached && video.current && !video.current.src && Hls.isSupported()) {
const hls = new Hls();
hls.loadSource(props.stream);
hls.loadSource(streamCached);
hls.attachMedia(video.current);
return () => hls.destroy();
}
}, [video, props]);
}, [video, streamCached]);
return (
<div>
<video ref={video} {...props} controls={true} />