TimeRanges: length 属性

Baseline 已广泛支持

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

TimeRanges.length 只读属性返回对象中范围的数量。

一个数字。

示例

给出一个 ID 为 "myVideo" 的视频元素

js
const v = document.getElementById("myVideo");

const buf = v.buffered;

const numRanges = buf.length;

if (buf.length === 1) {
  // Only one range
  if (buf.start(0) === 0 && buf.end(0) === v.duration) {
    // The one range starts at the beginning and ends at
    // the end of the video, so the whole thing is loaded
  }
}

此示例查看时间范围,并检查是否已加载整个视频。

规范

规范
HTML
# dom-timeranges-length-dev

浏览器兼容性