diff --git a/packages/app/src/pages/studio/tv/[profile_id]/components/StreamPreview/index.jsx b/packages/app/src/pages/studio/tv/[profile_id]/components/StreamPreview/index.jsx new file mode 100644 index 00000000..a90bcb94 --- /dev/null +++ b/packages/app/src/pages/studio/tv/[profile_id]/components/StreamPreview/index.jsx @@ -0,0 +1,44 @@ +import React from "react" +import Hls from "hls.js" + +const StreamPreview = ({ profile }) => { + const videoRef = React.useRef(null) + const hlsInstance = React.useRef(null) + + React.useEffect(() => { + hlsInstance.current = new Hls({ + maxLiveSyncPlaybackRate: 1.5, + strategy: "bandwidth", + autoplay: true, + }) + + hlsInstance.current.attachMedia(videoRef.current) + + hlsInstance.current.on(Hls.Events.MEDIA_ATTACHED, () => { + hlsInstance.current.loadSource(profile.sources.hls) + }) + + videoRef.current.addEventListener("play", () => { + console.log("[HLS] Syncing to last position") + videoRef.current.currentTime = hlsInstance.current.liveSyncPosition + }) + + videoRef.current.play() + + return () => { + hlsInstance.current.destroy() + } + }, []) + + return ( +