import { IconPatch } from "components/buttons/IconPatch"; import { Icons } from "components/Icon"; import { Loading } from "components/layout/Loading"; import { MWMediaCaption, MWMediaStream } from "providers"; import { ReactElement, useEffect, useRef, useState } from "react"; export interface VideoPlayerProps { source: MWMediaStream; captions: MWMediaCaption[]; startAt?: number; onProgress?: (event: ProgressEvent) => void; } export function SkeletonVideoPlayer(props: { error?: boolean }) { return (
{props.error ? (

Couldn't get your stream

) : (

Getting your stream...

)}
); } export function VideoPlayer(props: VideoPlayerProps) { const videoRef = useRef(null); const [hasErrored, setErrored] = useState(false); const [isLoading, setLoading] = useState(true); const showVideo = !isLoading && !hasErrored; const mustUseHls = props.source.type === "m3u8"; // reset if stream url changes useEffect(() => { setLoading(true); setErrored(false); }, [props.source.url]); let skeletonUi: null | ReactElement = null; if (hasErrored) { skeletonUi = ; } else if (isLoading) { skeletonUi = ; } return ( <> {skeletonUi} ); }