VTTCues represent a cue in a text track.
In order to create a new VTTCue, a new object must be instantiated by providing three arguments in the constructor:
startTime
in seconds: When the text will start to be displayedendTime
in seconds: When the text should be gonetext
: content to be presented in the media element
var cue = new VTTCue(2, 3, 'Cool text to be displayed');
Once the new cue is created, it can be added to an existing text track. A text track can be retrieved from the textTracks
list from a video element:
var tracks = document.querySelector('video').textTracks; var englishTrack = tracks[0]; englishTrack.addCue(cue);
Now, you can see the text "Cool test to be displayed" while playing a video, from second 2 to 3, and then it will be gone.