# new xdk-players-contrib/extensions/subtitles/AbstractExternal()
Abstract Class that can be used to hande any external subtitle that needs to be downloaded. The implementation will need to override the _parseSubtitles method.
Do not support regions for now. YOUR IMPLEMENTED PARSER SHOULD GROUP THE SUBTITLES
Requires fetch or a polyfill
By default this extension will fire SUBTITLE_UPDATE events that needs to be handled to render the subtitles
Example
import xdk, {environment, PlayerConstants, getSubtitleRenderer} from '@accedo/xdk-core';
import styles from '../style.module.css';
// ...
xdk.environment.addEventListener(SUBTITLE_UPDATE, getSubtitleRenderer({
className:styles["subtitle"]})
);
- Implements:
Methods
# protected __onTimeUpdate(currentTime)
Callback methods that is triggered every time the player sends a time update Is used to find an active text track and send it to the Subtitle renderer
Parameters:
Name | Type | Description |
---|---|---|
currentTime |
Integer
|
Current time in seconds |
# protected _downloadSubtitle(url) → {String}
Downloads the subtitle for the given URL and returns the content as a Requires fetch or a polyfill
Parameters:
Name | Type | Description |
---|---|---|
url |
String
|
URL where the subtitle is hosted |
Downloaded subtitle as a string
String
# protected _findTrackByStartingTime(seconds, seconds) → {SubtitleTrack}
Looks if there are available tracks for a given seconds as a starting time
Parameters:
Name | Type | Description |
---|---|---|
seconds |
Integer
|
|
seconds |
Integer
|
Subtitle track
SubtitleTrack
# protected _groupSubtitleTracks(Subtitle) → {GroupedTracks}
Optimization for the onTimeUpdate callback. Groups the subtitles by their second, to avoid to iterate over all the available tracks.
Parameters:
Name | Type | Description |
---|---|---|
Subtitle |
Array.<SubtitleTrack>
|
tracks |
Grouped tracks
GroupedTracks
# protected _parseSubtitles(text) → {Array.<SubtitleTrack>}
Abstract method. Get the subtitles in a text format and parse it to the SubtitleTrack array that this extension is able to handle
Parameters:
Name | Type | Description |
---|---|---|
text |
String
|
Text contaaining the subtitles to parse. |
Array of subtitle tracks
Array.<SubtitleTrack>
# protected _sanitizeSubtitles(subtitles) → {Array.<Object>}
Checks if the passed subtitles on the xdk.media.load method are correct
Parameters:
Name | Type | Description |
---|---|---|
subtitles |
Array.<Object>
|
Array object |
Array of sanitized subtitles
Array.<Object>
# deinit()
# getCurrentSubtitle()
- Implements:
# getSubtitles()
- Implements:
# hideSubtitle()
- Implements:
# init()
# prepare()
- Implements:
# showSubtitle()
- Implements:
Type Definitions
Object
# GroupedTracks
Properties:
Name | Type | Description |
---|---|---|
second |
Array.<SubtitleTrack>
|
i.e groupedTracks[0]. Subtitle tracks available on that second |
Object
# SubtitleTrack
Subtitle Tracks definition. Used on the subtitle methods and the initialization of the player for external subtitles. Based on Text Track from HTML5 https://developer.mozilla.org/en-US/docs/Web/API/TextTrack
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
startTime |
Number
|
Start time of the text track. |
|
startTiendTime |
Number
|
End time of the text track. |
|
text |
String
|
Text to render |
|
region |
String
|
<optional> |
Region to render the subtitle |