Live Stream Playback
Live Stream Playback
Once a stream is live, the HLS master playlist is available at:
https://worker.antcdn.net/live/{edgeId}/master.m3u8Get edgeId from playback.edgeId in the create stream or get stream response.
Native HTML5 (HLS.js)
Most browsers don’t support HLS natively (except Safari). Use hls.js for cross-browser support.
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<video id="player" controls></video>
<script> const video = document.getElementById('player'); const src = 'https://worker.antcdn.net/live/{edgeId}/master.m3u8';
if (Hls.isSupported()) { const hls = new Hls({ lowLatencyMode: false }); hls.loadSource(src); hls.attachMedia(video); } else if (video.canPlayType('application/vnd.apple.mpegurl')) { // Safari — native HLS video.src = src; }</script>React
import { useEffect, useRef } from 'react';import Hls from 'hls.js';
export function LivePlayer({ edgeId }: { edgeId: string }) { const videoRef = useRef<HTMLVideoElement>(null); const src = `https://worker.antcdn.net/live/${edgeId}/master.m3u8`;
useEffect(() => { const video = videoRef.current; if (!video) return;
if (Hls.isSupported()) { const hls = new Hls(); hls.loadSource(src); hls.attachMedia(video); return () => hls.destroy(); } else if (video.canPlayType('application/vnd.apple.mpegurl')) { video.src = src; } }, [src]);
return <video ref={videoRef} controls style={{ width: '100%' }} />;}Install hls.js:
npm install hls.jsVideo.js
<link href="https://vjs.zencdn.net/8/video-js.css" rel="stylesheet" /><script src="https://vjs.zencdn.net/8/video.min.js"></script>
<video id="player" class="video-js vjs-default-skin" controls> <source src="https://worker.antcdn.net/live/{edgeId}/master.m3u8" type="application/x-mpegURL" /></video>
<script> videojs('player', { fluid: true });</script>Checking Stream State Before Playing
Poll the stream state to show a “waiting for stream” message before the HLS feed is ready:
async function waitForLive(streamId, apiKey) { while (true) { const res = await fetch( `https://api.antcdn.net/v1/live-streams/${streamId}`, { headers: { Authorization: `Bearer ${apiKey}` } } ); const stream = await res.json(); if (stream.state === 'live') return stream.playback.hlsUrl; if (stream.state === 'ended' || stream.state === 'error') throw new Error(stream.state); await new Promise(r => setTimeout(r, 3000)); }}Latency
| Mode | Typical latency |
|---|---|
| Standard HLS | 4–8 seconds |
Low latency (lowLatency: true) | 1–3 seconds |
Enable low latency by setting "lowLatency": true when creating the stream. It increases segment request frequency — ensure your player supports LL-HLS or use hls.js with lowLatencyMode: true.