TimeRanges: end() 方法

Baseline 已广泛支持

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

TimeRanges 接口的 end() 方法返回指定时间范围结束的时间点(以秒为单位)。

语法

js
end(index)

参数

index

返回结束时间的范围编号。

返回值

一个数字。

异常

IndexSizeError DOMException

如果指定的索引不对应现有的范围,则抛出该异常。

示例

给定一个 ID 为 "myVideo" 的 video 元素

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-end-dev

浏览器兼容性