- Version
- 1.0.0
- License
- MIT
- Requires
- ExtendedMediaError
- Source
- Hls.js, line 14
Constructor
new Hls(player, mediaComponent, apiKey)
Members
private #config :Object
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
lazyLoadLib
|
boolean | optional | true | If |
libUrl
|
string | optional | Custom URL for the Hls.js library. Defaults to CDN URL if not specified. |
|
debug
|
boolean | optional | false | Enables verbose logging from the HLS component. |
private #player :Player
private #subscriptions :Array<number>
Holds tokens of subscriptions to player events, for later unsubscribe.
private #apiKey :symbol
Secret key only known to the player instance and initialized components. Used to be able to restrict access to API methods in conjunction with secure mode.
private #mediaComponent :Media
private #hls :Object
private #loadTask :AsyncTask
Reference to the Async Task instance. Used to handle async tasks, which can be cancelled, resolved or rejected.
private #metaData :Media~metaData
Holds metadata information provided by media.load and loaded metadata.
- Type
- Media~metaData
- Source
- Hls.js, line 69
private #loadHlsPromise :Promise
Methods
canPlay(metaData) → string
Checks if hls.js can handle the given mimeType and optional DRM system. ('Widevine').
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
metaData |
Media~metaData |
The data to test.
|
async load(metaData, optionsopt) → Promise|undefined
Initializes the hls.js library for a given source. Sets up the config (DRM if needed), attaches to the video stream, loads the HLS source.
| Name | Type | Attributes | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
metaData |
Media~metaData |
Source Object (currentSource).
|
|||||||||
options |
Object | optional |
Additional options.
|
private #loadHlsJs() → Promise<void>
Loads dash.js via CDN if not present. Ensures only one load attempt per instance.
onLoaded(metaData)
Called by the media component when metadata has loaded, but before the media/reafy event has been sent.
Allows the plugin to add additional metadata to the mediaSource object.
| Name | Type | Description |
|---|---|---|
metaData |
Media~metaData |
The source to load. |
private #onHlsLevelLoaded(event, data)
Called when a new Hls level is loaded. Updates 'islive' data attribute on the video element accordingly.
| Name | Type | Description |
|---|---|---|
event |
string |
The HLS LEVEL_LOADED event. |
data |
Object |
Video data. |
private #onMediaReady()
Called when the media metadata is loaded to initialize languages/qualities if needed.
- Listens
- media/ready
- Source
- Hls.js, line 304
private #onLanguageSelected(langObj)
Called when a language is selected in the language menu. Switches the HLS audio track accordingly.
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
langObj |
Language~langObj |
Object with selected language information.
|
- Listens
- language/selected
- Source
- Hls.js, line 343
private #onQualitySelected(quality)
Called when a quality is selected in the quality menu. Finds the matching level and sets it, or 'auto' if not found.
| Name | Type | Description |
|---|---|---|
quality |
string |
The chosen resolution, e.g. '720p'. |
- Listens
- quality/selected
- Source
- Hls.js, line 358
private #onHlsAudioSwitch(event, data)
Handler for the hls 'AUDIO_TRACK_SWITCHED' event. Publishes 'language/active' to sync the internal track with the player's language state.
| Name | Type | Description |
|---|---|---|
event |
string |
The HLS AUDIO_TRACK_SWITCHED event. |
data |
Object |
Newly selected audio track. |
- Fires
- language/active
- Source
- Hls.js, line 377
private #onHlsQualitySwitch(event, data)
Handler for the hls 'LEVEL_SWITCHED' event. Publishes 'quality/active' to sync the internal track with the player's language state.
| Name | Type | Description |
|---|---|---|
event |
string |
The HLS LEVEL_SWITCHED event. |
data |
Object |
Newly selected level. |
- Fires
- language/active
- Source
- Hls.js, line 393
private #onLogEvent(event, data)
Logs Hls.js events if debug is enabled.
| Name | Type | Description |
|---|---|---|
event |
string |
The hls debug event. |
data |
Object |
The original event data. |
private #onHlsError(event, data)
This method is responsible for translating errors coming from the HLS library, so that they can be handled like errors coming from the standard engine This is done by listening to selected events coming from the HLS library, and sending out errors via pubsub with the closest approximation to the standard HTML5 media error codes. In addition, the media error object is simulated by using a customized subclass of the standard error object.
| Name | Type | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
event |
Event |
The event coming from the HLS library. |
||||||||||||||||||||
data |
Object |
HLS Library event data.
|
- Fires
- media/error
- Source
- Hls.js, line 421
private #removeHls()
Removes the current HLS instance if present, unsubscribes from events, etc.
- Listens
- data/ready
- Source
- Hls.js, line 497