HTMLMediaElement: played 屬性

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

HTMLMediaElement 介面的只讀屬性 played 指示資源(<audio><video> 媒體檔案)已播放的時間範圍。它會返回一個新的 TimeRanges 物件,該物件包含在評估該屬性時瀏覽器已播放的媒體源的範圍(如果有)。

一個 TimeRanges 物件;表示已播放的時間範圍。

示例

js
const media = document.querySelector("audio");
const playedTimeRanges = media.played;
let timePlayed = 0;
// calculate the total time the media has played
for (let i = 0; i < playedTimeRanges.length; i++) {
  timePlayed += playedTimeRanges.end(i) - playedTimeRanges.start(i);
}
console.log(`The media played for a total of ${timePlayed} seconds.`);

規範

規範
HTML
# dom-media-played-dev

瀏覽器相容性

另見