TextTrackCueList: length 属性

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2015 年 7 月⁩以来,各浏览器均已提供此特性。

length 属性是 TextTrackCueList 接口的一个只读属性,它返回列表中提示的数量。

一个无符号长整型(unsigned long),表示列表中提示的数量。

示例

TextTrack.cues 属性返回一个 TextTrackCueList,其中包含该特定轨道上的当前提示。调用 cues.length 会返回列表中提示的数量。使用下面的 WebVTT 轨道,length 的值为 5。

WEBVTT

first
00:00:00.000 --> 00:00:00.999  line:80%
Hildy!

second
00:00:01.000 --> 00:00:01.499 line:80%
How are you?

third
00:00:01.500 --> 00:00:02.999 line:80%
Tell me, is the ruler of the universe in?

fourth
00:00:03.000 --> 00:00:04.299 line:80%
Yes, they're in - in a bad humor

fifth
00:00:04.300 --> 00:00:06.000 line:80%
Somebody must've stolen the crown jewels
js
const video = document.getElementById("video");
video.onplay = () => {
  console.log(video.textTracks[0].cues.length); // 5
};

规范

规范
HTML
# dom-texttrackcuelist-length

浏览器兼容性