import React from 'react' import Hls from 'hls.js' import { VideoPlaceholder } from './VideoPlaceholder' import './VideoElement.css' // streamUrl: string // loading: boolean // setProgress: (event: NativeEvent) => void // videoRef: useRef // startTime: number export function VideoElement({ streamUrl, loading, setProgress, videoRef, startTime, streamData }) { const [error, setError] = React.useState(false); function onLoad() { if (startTime) videoRef.current.currentTime = startTime; } React.useEffect(() => { if (!streamUrl.includes('.mp4')) { setError(false) if (!videoRef || !videoRef.current || !streamUrl || streamUrl.length === 0 || loading) return; const hls = new Hls(); if (!Hls.isSupported() && videoRef.current.canPlayType('application/vnd.apple.mpegurl')) { videoRef.current.src = streamUrl; return; } else if (!Hls.isSupported()) { setError(true) return; } hls.attachMedia(videoRef.current); hls.loadSource(streamUrl); } }, [videoRef, streamUrl, loading]); if (error) return (Your browser is not supported) if (loading) return Loading episode... if (!streamUrl || streamUrl.length === 0) return No video selected if (!streamUrl.includes('.mp4')) { return ( ) } else { return ( ) } }