我们的志愿者还没有将这篇文章翻译为 中文 (简体)加入我们帮助完成翻译!
您也可以阅读此文章的English (US)版。


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 displayed
  • endTime in seconds: When the text should be gone
  • text: 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];

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.