The TimedTextPlugin can be used to load a variety of different subtitle formats using predefined and/or custom parsers and renderers.

How to use

import {
IMSCParser,
IMSCRenderer,
TimedTextPlugin,
WebVTTParser,
WebVTTRenderer,
} from "@accurate-player/accurate-player-plugins";

import { SubtitleFormat } from "@accurate-player/accurate-player-core";

// Create plugin providing reference to player and list of parsers and renderers to use
const timedTextPlugin = new TimedTextPlugin(
player,
[WebVTTParser, IMSCParser],
[WebVTTRenderer, IMSCRenderer],
);

// Add subtitles
timedTextPlugin.add(
{
id: "vtt_sub",
src: "https://example.com/vtt_sub.vtt",
label: "VTT Subtitle",
enabled: true,
format: SubtitleFormat.VTT
},
{
id: "imsc_sub",
src: "https://example.com/imsc_sub.imsc",
label: "IMSC Subtitle",
enabled: false,
format: SubtitleFormat.IMSC
}
)

Hierarchy (view full)

Constructors

Properties

name: string
Name: string = TIMED_TEXT_PLUGIN_NAME

Accessors

  • get loaded(): boolean
  • Property that states whether this plugin considers itself ready for continued playback based on internal logic. Triggers internal event of type PlayerInternalEventType.LoadedChanged if property value was changed.

    Returns boolean

  • set loaded(loaded): void
  • Parameters

    • loaded: boolean

    Returns void

  • get muted(): boolean
  • Property that states whether this plugin considers itself muted based on internal logic. Triggers internal event of type PlayerInternalEventType.MutedChanged if property value was changed.

    Returns boolean

  • set muted(muted): void
  • Parameters

    • muted: boolean

    Returns void

  • get version(): string
  • Property describing the plugin name and version.

    Returns string

Methods

  • Adds (and loads) the given subtitles.

    Parameters

    Returns void

    Throws

    error if a parser for the subtitle format could not be found

    Throws

    error if a renderer for the subtitle format could not be found

  • Adds the given ques to the given subtitle.

    Cues with the same id are replaced.

    Parameters

    • idOrTimedTextReference: IdOrTimedTextReference

      the subtitle id or subtitle

    • cues: TimedTextCue[]

      the cues to add

    • triggerEvent: boolean = true

      determines if the changed event should be triggered by this add

    Returns void

    Throws

    error if one of the subtitles could not be found

  • Adds an event listener for a specific event.

    Parameters

    • type: string

      Event type.

    • callback: Listener

      Listener callback function.

    Returns void

  • Destroys the plugin and frees all resources.

    Returns void

  • Disables the given subtitles

    Parameters

    • Rest ...idsOrTimedTextReferences: IdOrTimedTextReference[]

      the subtitles

    Returns void

    Throws

    error if one of the subtitles could not be found

  • Enables the given subtitles

    Parameters

    • Rest ...idsOrTimedTextReferences: IdOrTimedTextReference[]

      the subtitles

    Returns void

    Throws

    error if one of the subtitles could not be found

  • Plugin actions are optional and by default a plugin does not contain any actions.

    Returns PluginAction[]

  • Returns the given subtitle

    Parameters

    • idOrTimedTextReference: IdOrTimedTextReference

      the subtitle

    Returns TimedTextReference

    Throws

    error if the subtitle could not be found

  • Retrieves timeline markers for a given subtitle track.

    Parameters

    • idOrTimedTextReference: IdOrTimedTextReference

      The ID or timed text reference.

    Returns CueMarker[]

    An array of cue markers representing the start and end frames of each cue in the subtitle track.

  • Alias method for removeEventListener.

    Parameters

    • type: string

      Event type.

    • callback: Listener

      Listener callback function.

    Returns void

  • Alias method for addEventListener.

    Parameters

    • type: string

      Event type.

    • callback: Listener

      Listener callback function.

    Returns void

  • Removes the given subtitles.

    Parameters

    • Rest ...idsOrTimedTextReferences: IdOrTimedTextReference[]

      the subtitles

    Returns void

    Throws

    error if one of the subtitles could not be found

  • Removes the given cues from the given subtitle.

    Parameters

    • idOrTimedTextReference: IdOrTimedTextReference

      the subtitle id or subtitle

    • idsOrTimedTextCues: IdOrTimedTextCue[]

      ids or cues to remove

    Returns void

    Throws

    error if one of the subtitles could not be found

  • Removes an event listener for a specific event.

    Parameters

    • type: string

      Event type.

    • callback: Listener

      Listener callback function.

    Returns void

  • Sets the offset (applied to cues) for the subtitle.

    Parameters

    • idOrTimedTextReference: IdOrTimedTextReference

      the subtitle

    • offset: TimeCode

      the offset to set in seconds

    Returns void

    Throws

    error if one of the subtitles could not be found

  • Sets the start time (negative offset) for the subtitle.s

    Parameters

    • idOrTimedTextReference: IdOrTimedTextReference

      the subtitle

    • startTime: TimeCode

      the start time to set in seconds

    Returns void

    Throws

    error if one of the subtitles could not be found

  • Toggles the enabled state of the given subtitles.

    Parameters

    • Rest ...idsOrTimedTextReferences: IdOrTimedTextReference[]

      the subtitles

    Returns void

    Throws

    error if one of the subtitles could not be found