HLS.js is a robust, open-source JavaScript library that implements an HLS (HTTP Live Streaming) client. It enables the playback of HLS streams directly in modern web browsers by leveraging the Media Source Extensions (MSE) API, eliminating the need for native browser HLS support. The current stable version is 1.6.16, with frequent patch releases addressing bug fixes and performance improvements. An active pre-release series, such as 1.7.0-alpha.1, indicates continuous development and upcoming significant changes. HLS.js differentiates itself through its extensive feature set, including adaptive bitrate streaming, DVR support, low-latency HLS (LL-HLS), DRM (via EME), CEA-608/708 captions, WebVTT subtitles, and advertising insertion, making it a comprehensive solution for HLS playback in web applications.
npm install hls.jsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize HLS.js, attach it to an HTML5 video element, load an HLS manifest, and handle common fatal errors for recovery. It includes a check for browser compatibility and a fallback for native HLS playback.
Migrate your project to use ES module `import` syntax. If using bundlers like Webpack with ESM, ensure the `workerPath` configuration option is set to point to `dist/hls.worker.js` if web workers are enabled. For older browser support, consider using the UMD/ES5 build or specific polyfills.
Refer to the HLS.js documentation on DRM and Encrypted Media Extensions (EME). Ensure correct manifest generation, key server responses, and `EXT-X-KEY` tag attributes. Updates in HLS.js v1.6.15 and v1.6.12 specifically address PlayReady and FairPlay parsing issues.
Applications implementing manual quality switching should explicitly pause the video (`video.pause()`) or set `video.playbackRate = 0` before changing `hls.currentLevel` and resume playback (`video.play()`) once the level switch is complete to prevent stalls.
HLS.js is a browser-specific library relying on Media Source Extensions. It is not designed for server-side processing or Node.js environments. Implement browser-side logic for HLS playback.
Avoid using alpha releases in production environments unless specifically testing new features. Consult the v1.7.0 milestone page and planning board on GitHub for detailed changes and migration guidance when a stable v1.7.0 is released.
Ensure HLS.js is imported using `import Hls from 'hls.js';` in modern module environments, or that the library's UMD build is loaded via a `<script>` tag before it's referenced, making `Hls` available globally.
Verify the manifest URL is correct and accessible. Check browser developer tools for network errors (404, 403, CORS issues) and server logs. Ensure the server is correctly configured to serve `.m3u8` files with appropriate MIME types and CORS headers. Load the manifest URL directly in a browser to confirm accessibility.
Review your DRM configuration, license server URL, and key acquisition process. Ensure `keyDrmSystem` is correctly specified and that the license server is responding with valid decryption keys for the content. Check browser console for EME-specific errors.
Implement a fallback for browsers without MSE support. For iOS Safari, this typically means directly assigning the HLS manifest URL to the `<video src>` attribute, as Safari has native HLS support. For other unsupported browsers, display an error message or provide an alternative player.
Implement error recovery mechanisms using `hls.recoverMediaError()` for `MEDIA_ERROR`. Check network conditions, server performance, and stream health. Adjust HLS.js configuration parameters related to buffering, such as `maxBufferLength` or `maxMaxBufferLength`, or `liveMaxLatencyDuration` for live streams.
No dependency data recorded yet.