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