Component
HLS Video Player
A headless HLS video player component with native HLS detection and error handling.
Installation
Usage
import { HLSVideoPlayer } from '@/components/hls-video-player'
<HLSVideoPlayer
ref={ref}
src="https://example.com/stream.m3u8"
width={1920}
height={1080}
onReady={onReady}
onHlsError={onHlsError}
/>Props
| Prop | Type | Description |
|---|---|---|
src | string | The HLS stream URL (.m3u8) or regular video source |
width | number | Video width (used for aspect ratio) |
height | number | Video height (used for aspect ratio) |
debug | boolean | Enable debug logging |
onHlsError | (error: HLSVideoError) => void | HLS error callback |
onVideoError | ReactEventHandler<HTMLVideoElement> | Native video error callback |
onReady | () => void | Called when video is ready to play |
onHlsLoaded | () => void | Called when HLS.js library is loaded |
startTime | number | Start playback at specific time (seconds) |
maxResolution | number | Cap max resolution (e.g., 720, 1080) |
minResolution | number | Set minimum resolution |
With Media Player Controls
Combine with the Media Player component for a full-featured video player UI:
Error Handling
import { type HLSVideoError } from '@/components/hls-video-player'
function App() {
const handleError = (error: HLSVideoError) => {
// error.type: 'network' | 'media' | 'fatal' | 'other'
// error.message: Human readable message
// error.fatal: Whether playback can continue
// error.details: Additional error details
if (error.fatal) {
// Show error UI, offer retry
}
}
return (
<HLSVideoPlayer
src="..."
width={1920}
height={1080}
onHlsError={handleError}
/>
)
}import { type HLSVideoError } from '@/components/hls-video-player'
function App() {
const handleError = (error: HLSVideoError) => {
// error.type: 'network' | 'media' | 'fatal' | 'other'
// error.message: Human readable message
// error.fatal: Whether playback can continue
// error.details: Additional error details
if (error.fatal) {
// Show error UI, offer retry
}
}
return (
<HLSVideoPlayer
src="..."
width={1920}
height={1080}
onHlsError={handleError}
/>
)
}