Captions Class
A class that creates captioning for multimedia content. Captions are
created from a dictionary of captions and can be played by alias. Captions
is a singleton class and depends on cloudkid.Audio
for the progress update.
Constructor
Captions
-
[captionDictionary=null]
-
[field=null]
Parameters:
-
[captionDictionary=null]
Dictionary optionalThe dictionary of captions
-
[field=null]
createjs.Text optionalAn text field to use as the output for this captions object
Example:
var captionsDictionary = {
"Alias1": [
{"start":0, "end":2000, "content":"Ohh that looks awesome!"}
],
"Alias2": [
{"start":0, "end":2000, "content":"Love it, absolutely love it!"}
]
};
var captions = new cloudkid.Captions(captionsDictionary);
captions.play("Alias1");
Item Index
Methods
- _calcUpdate
- _getTotalDuration
- _load
- _onSoundComplete
- _reset
- _timeCodeToMilliseconds
- _updateCaptions
- _updatePercent
- _updateToAnim
- destroy
- getFullCaption
- getMuteAll static
- hasCaption
- init static
- initialize
- isPlaying
- play
- run deprecated
- runWithAnimation deprecated
- seek
- setDictionary
- setMuteAll static
- setTextField
- stop
- updateTime
Methods
_calcUpdate
()
private
Calculates the captions after increasing the current time.
_getTotalDuration
()
private
Calculate the total duration of the current caption
_load
-
data
Sets an array of line data as the current caption data to play.
Parameters:
-
data
StringThe string
_onSoundComplete
()
private
Is called when cloudkid.Audio finishes playing. Is not called if a cloudkid.AudioAnimation finishes playing, as then stop() is called.
_reset
()
private
Reset the captions
_timeCodeToMilliseconds
-
input
Take the captions timecode and convert to milliseconds format is in HH:MM:ss:mmm
Parameters:
-
input
StringThe input string of the format
Returns:
Time in milliseconds
_updateCaptions
()
private
Updates the text in the managed text field.
_updatePercent
-
progress
Callback for when a frame is entered.
Parameters:
-
progress
NumberThe progress in the current sound as a percentage (0-1)
_updateToAnim
()
private
Callback for when a frame is entered, to sync to an animation's audio.
destroy
()
Destroy this load task and don't use after this
getFullCaption
-
alias
-
[separator="
A utility function for getting the full text of a caption by alias this can be useful for debugging purposes.
Parameters:
Returns:
The entire captions concatinated by the separator
getMuteAll
()
Bool
public
static
If the captions are all currently muted.
Returns:
Whether the captions are all muted
hasCaption
-
alias
Returns if there is a caption under that alias or not.
Parameters:
-
alias
StringThe alias to check against
Returns:
Whether the caption was found or not
init
-
[captionDictionary=null]
-
[field=null]
Creates the singleton instance of Captions, with an optional dictionary ready to go
Parameters:
-
[captionDictionary=null]
Object optionalAn object set up in dictionary format of caption objects.
-
[field=null]
createjs.Text optionalAn text field to use as the output for this captions object
initialize
-
[captionDictionary=null]
-
[field=null]
Constructor for caption.
Parameters:
-
[captionDictionary=null]
Object optionalAn object set up in dictionary format of caption objects.
-
[field=null]
createjs.Text | PIXI.Text | PIXI.BitmapText optionalAn text field to use as the output for this captions object. When using PIXI textfields, textIsProp should be false.
isPlaying
()
Bool
public
The playing status.
Returns:
If the caption is playing
play
-
alias
-
callback
Start the caption playback. Captions will tell cloudkid.Audio to play the proper sound.
Parameters:
Returns:
The update function that should be called if captions isSlave is true
run
-
alias
Starts caption playback without controlling the sound or animation. Returns the update function that should be called to control the Captions object.
Parameters:
-
alias
StringThe caption/sound alias
Returns:
The update function that should be called
runWithAnimation
-
animTimeline
Runs a caption synced to the audio of an animation.
Parameters:
-
animTimeline
cloudkid.AnimatorTimeline | cloudkid.PixiAnimator.AnimTimelineThe animation to sync to.
seek
-
time
Goto a specific time.
Parameters:
-
time
IntThe time in milliseconds to seek to in the captions
setDictionary
-
dict
Sets the dictionary object to use for captions. This overrides the current dictionary, if present.
Parameters:
-
dict
DictionaryThe dictionary object to use for captions.
setMuteAll
-
muteAll
Mute all of the captions.
Parameters:
-
muteAll
BoolWhether to mute or unmute
setTextField
-
field
Sets the CreateJS Text or Pixi BitmapText/Text object that Captions should control the text of. Only one text field can be controlled at a time. When using PIXI textfields, textIsProp should be false.
Parameters:
-
field
createjs.Text | PIXI.Text | PIXI.BitmapTextThe CreateJS or PIXI Text object
stop
()
public
Convience function for stopping captions. Is also called by cloudkid.AudioAnimation when it is finished.
updateTime
-
progress
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
IntThe time elapsed since the last frame in milliseconds
Properties
_animTimeline.
cloudkid.AnimatorTimeline | cloudkid.PixiAnimator.AnimTimeline
private
An animation timeline from Animator or PixiAnimator. This is used for syncing captions to audio that is synced with with an animation.
_captionDict
Dictionary
private
An object used as a dictionary with keys that should be the same as sound aliases
_currentDuration
Int
private
The duration in milliseconds of the current sound.
_currentLine
Int
private
Save the current line index
_currentTime
Int
private
The current playback time
_isDestroyed
Bool
private
If this instance has been destroyed already
_isSlave
Bool
private
If this Captions instance is a 'slave', that doesn't run cloudkid.Audio and must have update() called manually (and passed milliseconds). Default is false.
_lastActiveLine
Int
private
Cache the last active line
_muteAll
Bool
private
If you want to mute the captions, doesn't remove the current caption
_playing
Bool
private
If we're playing
_textField
createjs.Text | PIXI.Text | PIXI.BitmapText
private
A reference to the CreateJS Text object that Captions should be controlling. Only one text field can be controlled at a time. When using PIXI textfields, textIsProp should be false.
currentDuration
Int
Get the current duration of the current caption
isSlave
Bool
If this Captions instance is a 'slave', that doesn't run cloudkid.Audio and must have update() called manually (and passed milliseconds).
Default: false
textIsProp
Bool
private
If text should be set on the text field with '.text = ' instead of '.setText()'. When using PIXI textfields, textIsProp should be false. Default is true.