TextTrackCue object
The TextTrackCue object represents the individual cues, and provides methods and properties to access the data and events to act on changes to cue state.
![]() ![]() |
Syntax
var newCue = new TextTrackCue(startTime, endTime, text); // cue constructor
var firstCue = document.getElementById("trackElement").track.cues[0];
Members
The TextTrackCue object has these types of members:
Methods
The TextTrackCue object has these methods.
| Method | Description |
|---|---|
| addEventListener |
Registers an event handler for the specified event type. |
| dispatchEvent |
Sends an event to the current element. |
| getCueAsHTML |
Returns the TextTrackCue text (caption) as a document fragment consisting of HTML elements and other DOM nodes . |
| removeEventListener |
Removes an event handler that the addEventListener method registered. |
Properties
The TextTrackCue object has these properties.
| Property | Access type | Description |
|---|---|---|
| Read-only |
Returns the ending time, in seconds, for a text track cue. | |
| Read-only |
Returns the TextTrackCue, VideoTrack, or AudioTrack identifier. | |
| Read-only |
Returns the pause-on-exit flag on a TextTrackCue. When the flag is true, playback will pause when it reaches the cue's endTime. | |
| Read-only |
Returns the text track cue start time in seconds. | |
| Read-only |
Gets TextTrackCue text in un-parsed form. | |
| Read-only |
Returns the TextTrack object that the TextTrackCue belongs to, or null otherwise. |
Standards information
Remarks
Individual cues are returned from a TextTrackCueList object (collection of cues). In Internet Explorer 11, you can create cues using the constructor and add them to a track using addCue. To add a cue to a track, the track must be created in JavaScript using var newTrack = video.addTextTrack(kind, [label], [language]). The video is the video object that you're attaching the track to, and language and label are both optional.
Examples
The following example shows how to get and display all the text cues for a track.
<!DOCTYPE html > <html > <head> <title>Get track example</title> </head> <body> <h1>Get track example</h1> <video id="video1" controls > <source src="http://ie.microsoft.com/testdrive/Videos/BehindIE9ModernWebStandards/Video.mp4"> <track id="entrack" label="English subtitles" kind="captions" src="entrack.vtt" srclang="en" default> </video> <p> <button id="mybutton">Show tracks</button> </p> <div style="display:block; overflow:auto; height:200px; width:650px;" id="display"></div> <script> document.getElementById("mybutton").addEventListener("click", function () { var myTrack = document.getElementById("entrack").track; // get text track from track element var myCues = myTrack.cues; // get list of cues for (var i = 0; i < myCues.length; i++) { // append track label document.getElementById("display").innerHTML += (myCues[i].getCueAsHTML().textContent + "<br/>"); } }, false); </script> </body> </html>
See also

