Class: shaka.text.NativeTextDisplayer

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
Source:

timer_ :shaka.util.Timer

Timer used to debounce the textTracks 'change' event.
Type:
Source:

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:

visible_ :boolean

Type:
  • boolean
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.
Source:

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
Source:

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
Source:

checkMsePlayback_()

Initialises MSE integration if the player is already in MEDIA_SOURCE mode. Called from the constructor and again on each 'Loaded' event.
Source:

configure(config)

Sets the TextDisplayer configuration.
Parameters:
Name Type Description
config shaka.extern.TextDisplayerConfiguration
Implements:
Source:

createTrackNode_(tracknon-null) → {HTMLTrackElement}

Creates a new DOM element for the given track and appends it to the video element.
Parameters:
Name Type Description
track shaka.extern.TextTrack
Source:
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
Source:

getActiveTrack_() → {TextTrack}

Returns the active TextTrack, or null if none is currently active.
Source:
Returns:
Type
TextTrack

getTrackKind_(tracknon-null) → {string}

Returns the appropriate `kind` value for a element. WebKit requires the 'forced' kind for forced tracks; other browsers use 'captions' for closed captions and 'subtitles' as the default.
Parameters:
Name Type Description
track shaka.extern.TextTrack
Source:
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
Source:
Returns:
Type
string

isSrcEqualsMode_() → {boolean}

Returns true if the player is currently in SRC_EQUALS mode.
Source:
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.
Source:

onTextChanged_()

Synchronises the DOM elements with the player's track list. Creates elements for new tracks, reuses existing ones, and removes any that are no longer present.
Source:

onUnloading_()

Cleans up internal state when the player starts unloading content. Registered with listenOnce, so it fires at most once per playback session.
Source:

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.
Source:
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
Source:
Returns:
Type
string

reuseTrackNode_(tracknon-null) → {HTMLTrackElement}

Reuses an existing DOM node for a known track. Disables the node if the track is no longer active, and removes the entry from the original map so that onTextChanged_ can detect orphaned nodes.
Parameters:
Name Type Description
track shaka.extern.TextTrack
Source:
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
Source: