TimeRanges: start() 方法

Baseline 已广泛支持

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

TimeRanges 接口的 start() 方法返回指定时间范围开始的时间偏移量(以秒为单位)。

语法

js
start(index)

参数

index

要返回开始时间的范围编号。

返回值

一个数字。

异常

IndexSizeError DOMException

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

示例

给定一个 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-start-dev

浏览器兼容性