Scripts2026年5月20日·1 分钟阅读

HLS.js — HTTP Live Streaming Client for the Web

A JavaScript library that implements an HLS client, enabling playback of HTTP Live Streaming content in any browser with MediaSource Extensions support.

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Stage only · 17/100Stage only
Agent 入口
任意 MCP/CLI Agent
类型
CLI Tool
安装
Stage only
信任
信任等级:Established
入口
HLS.js Overview
通用 CLI 安装命令
npx tokrepo install 2e872258-548a-11f1-9bc6-00163e2b0d79

Introduction

HLS.js is a JavaScript library that brings HTTP Live Streaming (HLS) playback to browsers via the MediaSource Extensions API. It parses M3U8 playlists, manages segment fetching, handles adaptive bitrate switching, and feeds media data into a standard HTML5 video element without requiring native HLS support.

What HLS.js Does

  • Parses M3U8 master and variant playlists for multi-quality streams
  • Downloads and demuxes MPEG-TS and fMP4 segments in a web worker
  • Implements adaptive bitrate (ABR) switching based on bandwidth and buffer
  • Supports live, event, and VOD stream types with DVR window management
  • Handles DRM via Encrypted Media Extensions for protected content

Architecture Overview

HLS.js runs a loader pipeline that fetches playlist manifests and media segments over HTTP. A transmuxer in a Web Worker converts MPEG-TS containers to fragmented MP4 on the fly. Parsed media is appended to a MediaSource SourceBuffer, and the ABR controller monitors download speed and buffer levels to select the optimal quality level. The entire pipeline is event-driven and modular.

Self-Hosting & Configuration

  • Install from npm or load the UMD bundle from a CDN
  • Create an Hls instance and call loadSource() with your M3U8 URL
  • Attach to any HTML5 video element with attachMedia()
  • Tune ABR behavior with config options like maxBufferLength and abrBandWidthFactor
  • Enable low-latency mode with lowLatencyMode: true for LL-HLS streams

Key Features

  • Works in any browser that supports MediaSource Extensions
  • Adaptive bitrate switching with configurable bandwidth estimation
  • Web Worker-based transmuxing keeps the main thread responsive
  • Low-latency HLS (LL-HLS) support with partial segment loading
  • Subtitle and alternative audio track selection

Comparison with Similar Tools

  • dash.js — MPEG-DASH reference player; HLS.js focuses exclusively on the HLS protocol
  • Shaka Player — Supports both DASH and HLS with DRM; HLS.js is lighter and HLS-specific
  • Video.js + videojs-http-streaming — Full player with HLS plugin; HLS.js is the standalone engine
  • Native HLS (Safari) — Built into WebKit; HLS.js brings the same capability to Chrome and Firefox

FAQ

Q: Does HLS.js work in Safari? A: Safari has native HLS support. HLS.js detects this and can optionally fall back to native playback.

Q: Can I use HLS.js with a custom player UI? A: Yes. It only handles streaming logic and attaches to a plain video element. Pair it with Plyr or any UI layer.

Q: Does it support DRM-protected streams? A: Yes, via the Encrypted Media Extensions API. Configure emeEnabled and provide license server URLs.

Q: How do I handle live streams with DVR? A: HLS.js exposes a seekable range. Set liveSyncDuration and liveMaxLatencyDuration to control DVR window behavior.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产