fix: autoplay active vertical episode only

This commit is contained in:
Zhou Weidong committed 2026-11-10 16:19:58 +08:00
1 parent c816815132
commit b2e4374ddc
1 file changed
+1 -1
+1 -1
View File
@@ -4,6 +4,6 @@ import Hls from 'hls.js';
export function VideoPlayer({ src, poster, autoPlay = true, muted = true, onProgress }) {
const ref = useRef(null);
useEffect(() => { const video = ref.current; if (!video || !src) return undefined; const hls = new Hls(); if (video.canPlayType('application/vnd.apple.mpegurl')) video.src = src; else if (Hls.isSupported()) { hls.loadSource(src); hls.attachMedia(video); } const attempt = video.play(); attempt?.catch(() => {}); return () => { hls.destroy(); video.pause(); }; }, [src]);
useEffect(() => { const video = ref.current; if (!video || !src) return undefined; const hls = new Hls(); if (video.canPlayType('application/vnd.apple.mpegurl')) video.src = src; else if (Hls.isSupported()) { hls.loadSource(src); hls.attachMedia(video); } if (autoPlay) video.play().catch(() => {}); else video.pause(); return () => { hls.destroy(); video.pause(); }; }, [src, autoPlay]);
return <video ref={ref} className="video-player" poster={poster} controls playsInline autoPlay={autoPlay} muted={muted} onTimeUpdate={(event) => onProgress?.(event.currentTarget.currentTime)} />;
}