Fix error checking

This commit is contained in:
Nicolas Mowen 2024-03-13 14:15:10 -06:00
parent fd89b3c0ed
commit 5870cde614

View File

@ -43,6 +43,7 @@ export default function HlsVideoPlayer({
// playback // playback
const hlsRef = useRef<Hls>(); const hlsRef = useRef<Hls>();
const [useHlsCompat, setUseHlsCompat] = useState(false);
useEffect(() => { useEffect(() => {
if (!videoRef.current) { if (!videoRef.current) {
@ -52,8 +53,7 @@ export default function HlsVideoPlayer({
if (videoRef.current.canPlayType(HLS_MIME_TYPE)) { if (videoRef.current.canPlayType(HLS_MIME_TYPE)) {
return; return;
} else if (Hls.isSupported()) { } else if (Hls.isSupported()) {
hlsRef.current = new Hls(); setUseHlsCompat(true);
hlsRef.current.attachMedia(videoRef.current);
} }
}, [videoRef]); }, [videoRef]);
@ -64,15 +64,20 @@ export default function HlsVideoPlayer({
const currentPlaybackRate = videoRef.current.playbackRate; const currentPlaybackRate = videoRef.current.playbackRate;
if (!hlsRef.current) { if (!useHlsCompat) {
videoRef.current.src = currentSource; videoRef.current.src = currentSource;
videoRef.current.load(); videoRef.current.load();
return; return;
} }
if (!hlsRef.current) {
hlsRef.current = new Hls();
hlsRef.current.attachMedia(videoRef.current);
}
hlsRef.current.loadSource(currentSource); hlsRef.current.loadSource(currentSource);
videoRef.current.playbackRate = currentPlaybackRate; videoRef.current.playbackRate = currentPlaybackRate;
}, [videoRef, hlsRef, currentSource]); }, [videoRef, hlsRef, useHlsCompat, currentSource]);
// controls // controls
@ -186,8 +191,7 @@ export default function HlsVideoPlayer({
e.target.error.code == MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED && e.target.error.code == MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED &&
videoRef.current videoRef.current
) { ) {
hlsRef.current = new Hls(); setUseHlsCompat(true);
hlsRef.current.attachMedia(videoRef.current);
} }
}} }}
/> />