Constructor
new NativeTextDisplayer(player)
Parameters:
| Name | Type | Description |
|---|---|---|
player |
shaka.Player |
- Implements:
- Source:
Members
LoadMode :number
Named constants mirroring shaka.Player.LoadMode to avoid magic numbers.
Type:
- number
Properties:
| Name | Value | Type | Description |
|---|---|---|---|
MEDIA_SOURCE |
2 | number | |
SRC_EQUALS |
3 | number |
trackId_ :number
ID of the currently active text track. -1 means no track is active.
Type:
- number
- Source:
trackNodes_ :Map<number, !HTMLTrackElement>
Type:
- Map<number, !HTMLTrackElement>
- Source:
Methods
activateCurrentTrack_()
Activates the track identified by this.trackId_ among the newly built
nodes, respecting the current mode if it was changed manually by the user.
append(cuesnon-null)
Appends cues to the active track, applying the subtitle delay if set.
Parameters:
| Name | Type | Description |
|---|---|---|
cues |
Array<!shaka.text.Cue> | Text cues to be appended. |
- Implements:
- Source:
applyVisibilityToSrcEqualsTracks_(on)
Manages subtitle visibility in SRC_EQUALS mode, where tracks are controlled
directly by the HTMLMediaElement rather than MSE.
Parameters:
| Name | Type | Description |
|---|---|---|
on |
boolean |
applyVisibilityToTrack_(track, visible)
Applies the visibility mode to a specific track without touching tracks
that are already 'disabled' (e.g. manually turned off by the user).
Parameters:
| Name | Type | Description |
|---|---|---|
track |
TextTrack | |
visible |
boolean |
checkMsePlayback_()
Initialises MSE integration if the player is already in MEDIA_SOURCE mode.
Called from the constructor and again on each 'Loaded' event.
configure(config)
Sets the TextDisplayer configuration.
Parameters:
| Name | Type | Description |
|---|---|---|
config |
shaka.extern.TextDisplayerConfiguration |
- Implements:
- Source:
createTrackNode_(tracknon-null) → {HTMLTrackElement}
Creates a new
Parameters:
| Name | Type | Description |
|---|---|---|
track |
shaka.extern.TextTrack |
Returns:
- Type
- HTMLTrackElement
disableAllTracksExcept_(keepTrackId)
Sets all tracks except the specified one to 'disabled', avoiding
unnecessary change events on tracks that are already disabled.
Parameters:
| Name | Type | Description |
|---|---|---|
keepTrackId |
number |
getActiveTrack_() → {TextTrack}
Returns the active TextTrack, or null if none is currently active.
Returns:
- Type
- TextTrack
getTrackKind_(tracknon-null) → {string}
Returns the appropriate `kind` value for a
Parameters:
| Name | Type | Description |
|---|---|---|
track |
shaka.extern.TextTrack |
Returns:
- Type
- string
getTrackLabel_(tracknon-null) → {string}
Builds a human-readable label for a track. Priority order:
1. track.label (if explicitly set)
2. Intl.DisplayNames resolution (when available)
3. Full language name from LanguageMapping (exact match)
4. Base language name from LanguageMapping with variant in parentheses
5. originalTextId with the language code in parentheses if they differ
Parameters:
| Name | Type | Description |
|---|---|---|
track |
shaka.extern.TextTrack |
Returns:
- Type
- string
isSrcEqualsMode_() → {boolean}
Returns true if the player is currently in SRC_EQUALS mode.
Returns:
- Type
- boolean
isTextVisible() → {boolean}
Returns true if text is currently visible.
- Implements:
- Source:
Returns:
- Type
- boolean
onChange_()
Handles manual changes to the video's textTracks (e.g. the user enables a
track through the browser's native subtitle menu). Applies debounce because
the 'change' event can fire multiple times in quick succession.
onUnloading_()
Cleans up internal state when the player starts unloading content.
Registered with listenOnce, so it fires at most once per playback session.
remove(startTime, endTime) → {boolean}
Removes cues whose time range overlaps with [start, end).
Returns false only if this instance has already been destroyed.
Parameters:
| Name | Type | Description |
|---|---|---|
startTime |
number | |
endTime |
number |
- Implements:
- Source:
Returns:
- Type
- boolean
resolveActiveTrackId_() → {number}
Determines which track should be active after a 'change' event.
Prefers the previously selected track; otherwise picks the first 'showing'
track, and falls back to the first 'hidden' track.
Returns:
The ID of the track to activate, or -1 if none.
- Type
- number
resolveTrackLanguage_(tracknon-null) → {string}
Resolves the appropriate srclang value for a track based on its declared
language. Falls back to 'und' (undetermined) if the language is unknown.
Parameters:
| Name | Type | Description |
|---|---|---|
track |
shaka.extern.TextTrack |
Returns:
- Type
- string
reuseTrackNode_(tracknon-null) → {HTMLTrackElement}
Reuses an existing
Parameters:
| Name | Type | Description |
|---|---|---|
track |
shaka.extern.TextTrack |
Returns:
- Type
- HTMLTrackElement
setTextLanguage(language)
Set the current language.
Parameters:
| Name | Type | Description |
|---|---|---|
language |
string |
- Implements:
- Source:
setTextVisibility(on)
Shows or hides subtitles. Handles both MSE and SRC_EQUALS playback modes.
Parameters:
| Name | Type | Description |
|---|---|---|
on |
boolean |
- Implements:
- Source:
syncTrackSelectionWithPlayer_(trackId)
Notifies the player of the newly selected track, or clears the selection
if trackId is -1.
Parameters:
| Name | Type | Description |
|---|---|---|
trackId |
number |