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

瀏覽器相容性