Captions Events

These API calls are used to listen to or update the active captions track if one or more closed captions tracks are provided with a video. The JavaScript API can be used to log captions usage or build your own CC menu outside JW Player. It is also possible to set caption styles dynamically using setCaptions() without having to reload the player.

πŸ“˜

An index of 0 implies that captions are off.


.on('captionsList')

Fires when the list of available captions tracks changes

This event is the ideal time to set default captions with the API.

πŸ“˜

captionsList will always return an array of at least 1 item due to off, but will trigger again once captions are fully loaded. We suggest only changing captions when the tracks array length exceeds 1.

{
    "tracks": [
        {
            "id": "off",
            "label": "Off"
        },
        {
            "id": "//playertest-cdn.longtailvideo.com/assets/os/captions/bunny-en.srt",
            "label": "English",
            "language": "en"
        }
    ],
    "track": 0,
    "type": "captionsList"
}
Property Description
track number Index of the active captions track
tracks array All included captions tracks

See: tracks[]
type string Category of player event

This is always captionsList for this event.

tracks[]

Property Description
id string | number (Sideloaded Captions: .srt, .vtt) URL of the sideloaded captions file

(Embedded Captions: .vtt, CEA-608, CEA-708) Index of the caption

NOTE: The id value of the first tracks[] object is always off. The first track indicates that captions are off.
label string (Sideloaded Captions: .srt, .vtt) Label configured in the player setup

(Embedded Captions: .vtt, CEA-608, CEA-708) Label specified within the embedded captions

NOTE: The label value of the first tracks[] object is always Off. The first track indicates that captions are off.
language string Two-letter language abbreviation for the captions track


.on('captionsChanged')

Triggers whenever the active captions track is changed manually or via API

{
    "tracks": [
        {
            "id": "off",
            "label": "Off"
        },
        {
            "id": "//playertest-cdn.longtailvideo.com/assets/os/captions/bunny-en.srt",
            "label": "English",
            "language": "en"
        }
    ],
    "track": 0,
    "type": "captionsChanged"
}
Property Description
track number Index of the new active captions track
tracks array All included captions tracks

See: tracks[]
type string Category of player event

This is always captionsChanged for this event.

tracks[]

Property Description
id string | number (Sideloaded Captions: .srt, .vtt) URL of the sideloaded captions file

(Embedded Captions: .vtt, CEA-608, CEA-708) Index of the caption

NOTE: The id value of the first tracks[] object is always off. The first track indicates that captions are off.
label string (Sideloaded Captions: .srt, .vtt) Label configured in the player setup

(Embedded Captions: .vtt, CEA-608, CEA-708) Label specified within the embedded captions

NOTE: The label value of the first tracks[] object is always Off. The first track indicates that captions are off.
language string Two-letter language abbreviation for the captions track