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

瀏覽器相容性