HTMLMediaElement: played 屬性
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 |
瀏覽器相容性
載入中…