fix: preserve signed query for HLS segments
This commit is contained in:
1 parent
ab820253cd
commit
e7c4d01a93
1 file changed
+5
-1
@@ -2,8 +2,12 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
import Hls from 'hls.js';
|
||||
|
||||
class SignedRequestLoader extends Hls.DefaultConfig.loader {
|
||||
load(context, config, callbacks) { const source = new URL(context.url, window.location.href); const original = new URL(this.sourceUrl || context.url, window.location.href); if (!source.search && original.search) source.search = original.search; context.url = source.toString(); return super.load(context, config, callbacks); }
|
||||
}
|
||||
|
||||
export function VideoPlayer({ src, poster, autoPlay = true, muted = true, onProgress }) {
|
||||
const ref = useRef(null);
|
||||
useEffect(() => { const video = ref.current; if (!video || !src) return undefined; video.muted = muted; const hls = new Hls({ enableWorker: true }); const start = () => { if (autoPlay) video.play().catch(() => {}); else video.pause(); }; if (video.canPlayType('application/vnd.apple.mpegurl')) { video.src = src; video.addEventListener('loadedmetadata', start, { once: true }); } else if (Hls.isSupported()) { hls.on(Hls.Events.MANIFEST_PARSED, start); hls.loadSource(src); hls.attachMedia(video); } return () => { video.removeEventListener('loadedmetadata', start); hls.destroy(); video.pause(); }; }, [src, autoPlay, muted]);
|
||||
useEffect(() => { const video = ref.current; if (!video || !src) return undefined; video.muted = muted; const hls = new Hls({ enableWorker: true, loader: class extends SignedRequestLoader { constructor(config) { super(config); this.sourceUrl = src; } } }); const start = () => { if (autoPlay) video.play().catch(() => {}); else video.pause(); }; if (video.canPlayType('application/vnd.apple.mpegurl')) { video.src = src; video.addEventListener('loadedmetadata', start, { once: true }); } else if (Hls.isSupported()) { hls.on(Hls.Events.MANIFEST_PARSED, start); hls.loadSource(src); hls.attachMedia(video); } return () => { video.removeEventListener('loadedmetadata', start); hls.destroy(); video.pause(); }; }, [src, autoPlay, muted]);
|
||||
return <video ref={ref} className="video-player" poster={poster} controls playsInline autoPlay={autoPlay} muted={muted} onTimeUpdate={(event) => onProgress?.(event.currentTarget.currentTime)} />;
|
||||
}
|
||||
Reference in new issue
Block a user