HTMLMediaElement: thuộc tính played
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Thuộc tính chỉ đọc played của giao diện HTMLMediaElement cho biết khoảng thời gian mà tài nguyên, tệp phương tiện <audio> hoặc <video>, đã phát. Nó trả về một đối tượng TimeRanges mới chứa các phạm vi của nguồn phương tiện mà trình duyệt đã phát, nếu có, tại thời điểm thuộc tính được đánh giá.
Giá trị
Một đối tượng TimeRanges; đại diện cho phạm vi thời gian đã được chơi.
Ví dụ
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.`);
Đặc tả kỹ thuật
| Specification |
|---|
| HTML> # dom-media-played-dev> |