springroll.Captions Class

Module: Captions

A class that creates captioning for multimedia content. Captions are created from a dictionary of captions and can be played by alias.

Constructor

springroll.Captions

(
  • [data=null]
  • [textField=null]
  • [selfUpdate=true]
)

Parameters:

  • [data=null] Object optional

    The captions dictionary

  • [textField=null] String | DOMElement optional

    The output text field

  • [selfUpdate=true] Boolean optional

    If the captions playback should update itself

Example:

    var captionsData = {
        "Alias1": [
            {"start":0, "end":2000, "content":"Ohh that looks awesome!"}
        ],
        "Alias2": [
            {"start":0, "end":2000, "content":"Love it, absolutely love it!"}
        ]
    };

    //initialize the captions
    var captions = new springroll.Captions();
    captions.data = captionsData;
    captions.textField = document.getElementById("captions");
    captions.play("Alias1");

_calcUpdate

()
private

Defined in _calcUpdate:609

Calculates the captions after increasing the current time.

_getTotalDuration

()
private

Calculate the total duration of the current caption

_load

(
  • data
)
private

Defined in _load:390

Sets an array of line data as the current caption data to play.

Parameters:

_reset

()
private

Defined in _reset:412

Reset the captions

_timeCodeToMilliseconds

(
  • input
)
Int
private

Take the captions timecode and convert to milliseconds format is in HH:MM:ss:mmm

Parameters:

  • input String

    The input string of the format

Returns:

Int:

Time in milliseconds

_updateCaptions

()
private

Defined in _updateCaptions:647

Updates the text in the managed text field.

_updatePercent

(
  • progress
)
private

Defined in _updatePercent:580

Callback for when a frame is entered.

Parameters:

  • progress Number

    The progress in the current sound as a percentage (0-1)

destroy

()

Defined in destroy:696

Destroy this load task and don't use after this

getFullCaption

(
  • alias
  • [separator=" "]
)
String

Defined in getFullCaption:328

A utility function for getting the full text of a caption by alias this can be useful for debugging or tracking purposes.

Parameters:

  • alias String | Array

    The alias or Array of aliases for which to get the text. Any non-String values in this Array are silently and harmlessly ignored.

  • [separator=" "] String optional

    The separation between each line.

Returns:

String:

The entire caption, concatinated by the separator.

getLength

(
  • alias
)
Int

Defined in getLength:660

Returns duration in milliseconds of given captioned sound alias or alias list.

Parameters:

  • alias String | Array

    The alias or array of aliases for which to get duration. Array may contain integers (milliseconds) to account for un-captioned gaps.

Returns:

Int:

Length/duration of caption in milliseconds.

hasCaption

(
  • alias
)
Boolean

Defined in hasCaption:317

Returns if there is a caption under that alias or not.

Parameters:

  • alias String

    The alias to check against

Returns:

Boolean:

Whether the caption was found or not

play

(
  • alias
  • callback
)
public

Defined in play:494

Start the caption playback.

Parameters:

  • alias String

    The desired caption's alias

  • callback Function

    The function to call when the caption is finished playing

seek

(
  • time
)
public

Defined in seek:528

Goto a specific time.

Parameters:

  • time Int

    The time in milliseconds to seek to in the captions

setText

(
  • field
  • text
)
createjs.Text | PIXI.Text | PIXI.BitmapText | DOMElement
private static

Defined in setText:285

Automatically determine how to set the text field text

Parameters:

Returns:

createjs.Text | PIXI.Text | PIXI.BitmapText | DOMElement:

The text field

stop

()
public

Defined in stop:513

Convience function for stopping captions.

update

(
  • progress
)
public

Defined in update:594

Function to update the amount of time elapsed for the caption playback. Call this to advance the caption by a given amount of time.

Parameters:

  • progress Int

    The time elapsed since the last frame in milliseconds

_completeCallback

Function private

The function to call when playback is complete.

_currentAlias

String private

Defined in _currentAlias:69

The alias of the current caption.

_currentDuration

Int private

Defined in _currentDuration:76

The duration in milliseconds of the current caption.

_currentLine

Int private

Defined in _currentLine:90

The current line index.

_currentTime

Int private

Defined in _currentTime:83

The current playback time, in milliseconds.

_data

Object private

Defined in _data:40

An object used as a dictionary with keys that should be the same as sound aliases

_destroyed

Boolean private

Defined in _destroyed:111

If this instance has been destroyed already.

_lastActiveLine

Int private

Defined in _lastActiveLine:97

The last active line index.

_lines

Array private

Defined in _lines:62

The collection of line objects - {start:0, end:0, content:""}

_mute

Boolean private

Defined in _mute:126

If the captions are muted

Default: false

_playing

Boolean private

Defined in _playing:104

If we're playing.

_selfUpdate

Boolean private

Defined in _selfUpdate:118

If the captions object should do its own update.

Default: true

_textField

createjs.Text | PIXI.Text | PIXI.BitmapText | DOMElement private

Defined in _textField:47

A reference to the Text object that Captions should be controlling. Only one text field can be controlled at a time.

currentAlias

String

Defined in currentAlias:481

Get the current caption alias.

currentDuration

Int

Defined in currentDuration:468

Get the current duration of the current caption

data

Object

Defined in data:195

Sets the dictionary object to use for captions. This overrides the current dictionary, if present.

mute

Boolean

Defined in mute:152

Set if all captions are currently muted.

Default: false

p

Object private static

Defined in p:144

Reference to the prototype

playing

Boolean public

Defined in playing:443

The playing status.

selfUpdate

Boolean

Defined in selfUpdate:170

If the captions object should do it's own updating unless you want to manuall seek. In general, self-updating should not be set to false unless the sync of the captions needs to be exact with something else.

Default: true

textField

String | createjs.Text | PIXI.Text | PIXI.BitmapText | DOMElement

Defined in textField:266

The text field that the captions uses to update.