Home > hls.js > Hls

Hls class

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

Signature:

export default class Hls implements HlsEventEmitter 

Implements: HlsEventEmitter

Constructors

Constructor

Modifiers

Description

(constructor)(userConfig)

Creates an instance of an HLS client that can attach to exactly one HTMLMediaElement.

Properties

Property

Modifiers

Type

Description

abrEwmaDefaultEstimate

readonly

number

allAudioTracks

readonly

MediaPlaylist[]

Get the complete list of audio tracks across all media groups

allSubtitleTracks

readonly

MediaPlaylist[]

get the complete list of subtitle tracks across all media groups

audioTrack

number

index of the selected audio track (index in audio track lists)

audioTracks

readonly

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

number

Returns the current bandwidth estimate in bits per second, when available. Otherwise, NaN is returned.

bufferedToEnd

readonly

boolean

returns true when all SourceBuffers are buffered to the end

bufferingEnabled

readonly

boolean

Returns state of fragment loading toggled by calling pauseBuffering() and resumeBuffering().

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

ErrorDetails

static

readonly

typeof ErrorDetails

ErrorTypes

static

readonly

typeof ErrorTypes

Events

static

readonly

typeof Events

firstAutoLevel

readonly

number

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

hasEnoughToStart

readonly

boolean

Whether or not enough has been buffered to seek to start position or use media.currentTime to determine next load position

interstitialsManager

readonly

InterstitialsManager | null

returns Interstitials Program Manager

latency

readonly

number

Estimated position (in seconds) of live edge (ie edge of live playlist plus time sync playlist advanced)

latestLevelDetails

readonly

LevelDetails | null

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```)

loadingEnabled

readonly

boolean

Returns whether loading, toggled with startLoad() and stopLoad(), is active or not`.

loadLevel

number

Return the quality level of the currently or last (of none is loaded currently) segment

logger

readonly

ILogger

The logger functions used by this player instance, configured on player instantiation.

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

maxBufferLength

readonly

number

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

MetadataSchema

static

readonly

typeof MetadataSchema

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

pathwayPriority

string[] | null

ContentSteering pathwayPriority getter/setter

playingDate

readonly

Date | null

get the datetime value relative to media.currentTime for the active level Program Date Time if present

sessionId

readonly

string

startLevel

number

Return the desired start level for the first fragment that will be loaded. The default value of -1 indicates automatic start level selection. Setting hls.nextAutoLevel without setting a startLevel will result in the nextAutoLevel value being used for one fragment load.

startPosition

readonly

number

Get the startPosition set on startLoad(position) or on autostart with config.startPosition

subtitleDisplay

boolean

Whether subtitle display is enabled or not

subtitleTrack

number

index of the selected subtitle track (index in subtitle track lists)

subtitleTracks

readonly

MediaPlaylist[]

get alternate subtitle tracks list from playlist

targetLatency

number | null

target distance from the edge as calculated by the latency controller

ttfbEstimate

readonly

number

get time to first byte estimate {number}

url

readonly

string | null

Gets the currently loaded URL

userConfig

readonly

Partial<HlsConfig>

The configuration object provided on player instantiation.

version

static

readonly

string

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

Methods

Method

Modifiers

Description

attachMedia(data)

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)

getMediaDecodingInfo(level, audioTracks)

returns mediaCapabilities.decodingInfo for a variant/rendition

getMediaSource()

static

Get the MediaSource global used for MSE playback (ManagedMediaSource, MediaSource, or WebKitMediaSource).

isMSESupported()

static

Check if the required MediaSource Extensions are available.

isSupported()

static

Check if MediaSource Extensions are available and isTypeSupported checks pass for any baseline codecs.

listenerCount(event)

listeners(event)

loadSource(url)

Set the source URL. Can be relative or absolute.

off(event, listener, context, once)

on(event, listener, context)

once(event, listener, context)

pauseBuffering()

Prevents stream controller from loading new segments until resumeBuffering is called. This allows for media buffering to be paused without interupting playlist loading.

recoverMediaError()

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.

removeAllListeners(event)

removeLevel(levelIndex)

resumeBuffering()

Resumes stream controller segment loading after pauseBuffering has been called.

setAudioOption(audioOption)

Find and select the best matching audio track, making a level switch when a Group change is necessary. Updates hls.config.audioPreference. Returns the selected track, or null when no matching track is found.

setSubtitleOption(subtitleOption)

Find and select the best matching subtitle track, making a level switch when a Group change is necessary. Updates hls.config.subtitlePreference. Returns the selected track, or null when no matching track is found.

startLoad(startPosition, skipSeekToStartPosition)

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)

transferMedia()

Detach HTMLMediaElement, MediaSource, and SourceBuffers without reset, for attaching to another instance

trigger(event, eventObject)