Home > hls.js > Hls

Hls class

The Hls class is the core of the HLS.js library used to instantiate player instances.


export default class Hls implements HlsEventEmitter 

Implements: HlsEventEmitter


Constructor Modifiers Description
(constructor)(userConfig) Creates an instance of an HLS client that can attach to exactly one HTMLMediaElement.


Property Modifiers Type Description
audioTrack number index of the selected audio track (index in audio track lists)
audioTracks readonly Array<MediaPlaylist> Get the list of selectable audio tracks
autoLevelCapping number Capping/max level value that should be used by automatic level selection algorithm (ABRController)
autoLevelEnabled readonly boolean True when automatic level selection enabled
bandwidthEstimate readonly number Returns the current bandwidth estimate in bits per second, when available. Otherwise, NaN is returned.
capLevelToPlayerSize boolean Whether level capping is enabled. Default value is set via config.capLevelToPlayerSize.
config readonly HlsConfig The runtime configuration used by the player. At instantiation this is combination of hls.userConfig merged over Hls.DefaultConfig.
currentLevel number Index of quality level (variant) currently played
DefaultConfig static HlsConfig Get the default configuration applied to new instances.
drift readonly number | null the rate at which the edge of the current live playlist is advancing or 1 if there is none



typeof ErrorDetails



typeof ErrorTypes



typeof Events
firstLevel number Return "first level": like a default level, if not set, falls back to index of first level referenced in manifest
forceStartLoad readonly boolean set to true when startLoad is called before MANIFEST_PARSED event
latency readonly number Estimated position (in seconds) of live edge (ie edge of live playlist plus time sync playlist advanced)
levels readonly Level[]
liveSyncPosition readonly number | null Position (in seconds) of live sync point (ie edge of live position minus safety delay defined by ```hls.config.liveSyncDuration```)
loadLevel number Return the quality level of the currently or last (of none is loaded currently) segment
lowLatencyMode boolean get mode for Low-Latency HLS loading
mainForwardBufferInfo readonly BufferInfo | null
manualLevel readonly number Level set manually (if any)
maxAutoLevel readonly number max level selectable in auto mode according to autoLevelCapping
maxHdcpLevel HdcpLevel
maxLatency readonly number maximum distance from the edge before the player seeks forward to ```hls.liveSyncPosition``` configured using ```liveMaxLatencyDurationCount``` (multiple of target duration) or ```liveMaxLatencyDuration```
media readonly HTMLMediaElement | null
minAutoLevel readonly number min level selectable in auto mode according to config.minAutoBitrate
nextAutoLevel number next automatically selected quality level
nextLevel number Index of next quality level loaded as scheduled by stream controller.
nextLoadLevel number get next quality level loaded
playingDate readonly Date | null get the datetime value relative to media.currentTime for the active level Program Date Time if present
startLevel number Return start level (level of first fragment that will be played back) if not overrided by user, first level appearing in manifest will be used as start level if -1 : automatic start level selection, playback will start from level matching download bandwidth (determined from download of first segment)
subtitleDisplay boolean Whether subtitle display is enabled or not
subtitleTrack number index of the selected subtitle track (index in subtitle track lists)
subtitleTracks readonly Array<MediaPlaylist> get alternate subtitle tracks list from playlist
targetLatency readonly number | null target distance from the edge as calculated by the latency controller
ttfbEstimate readonly number get time to first byte estimate {number}
userConfig readonly Partial<HlsConfig> The configuration object provided on player instantiation.



string Get the video-dev/hls.js package version.


Method Modifiers Description
attachMedia(media) Attaches Hls.js to a media element
createController(ControllerClass, components)
destroy() Dispose of the instance
detachMedia() Detach Hls.js from the media
emit(event, name, eventObject)
isSupported() static Check if the required MediaSource Extensions are available.
loadSource(url) Set the source URL. Can be relative or absolute.
off(event, listener, context, once)
on(event, listener, context)
once(event, listener, context)

When the media-element fails, this allows to detach and then re-attach it as one call (convenience method).

Automatic recovery of media-errors by this process is configurable.

removeLevel(levelIndex, urlId)
startLoad(startPosition) Start loading data from the stream source. Depending on default config, client starts loading automatically when a source is set.
stopLoad() Stop loading of any stream data.
swapAudioCodec() Swap through possible audio codecs in the stream (for example to switch from stereo to 5.1)
trigger(event, eventObject)