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 |
|---|---|---|---|
| allAudioTracks | readonly |
Array<MediaPlaylist> | Get the complete list of audio tracks across all media groups |
| allSubtitleTracks | readonly |
Array<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 |
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 | 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 |
| ErrorDetails |
|
typeof ErrorDetails | |
| ErrorTypes |
|
typeof ErrorTypes | |
| Events |
|
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 |
| 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 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. | |
| 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. |
| version |
|
string | Get the video-dev/hls.js package version. |
Methods
| 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) | ||
| 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) | 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) |