HTMLMediaElement: progress イベント
progress
イベントは、ブラウザーがリソースを読み込むときに定期的に発生します。
このイベントはキャンセル不可で、バブリングしません。
構文
このイベントを addEventListener()
などのメソッドで使用するか、イベントハンドラープロパティを設定するかしてください。
js
addEventListener("progress", (event) => {});
onprogress = (event) => {};
イベント型
一般的な Event
です。
例
ライブデモ
HTML
html
<div class="example">
<button type="button">Load video</button>
<video controls width="250"></video>
<div class="event-log">
<label for="eventLog">Event log:</label>
<textarea readonly class="event-log-contents" id="eventLog"></textarea>
</div>
</div>
JavaScript
js
const loadVideo = document.querySelector("button");
const video = document.querySelector("video");
const eventLog = document.querySelector(".event-log-contents");
let source = null;
function handleEvent(event) {
eventLog.textContent += `${event.type}\n`;
}
video.addEventListener("loadstart", handleEvent);
video.addEventListener("progress", handleEvent);
video.addEventListener("canplay", handleEvent);
video.addEventListener("canplaythrough", handleEvent);
loadVideo.addEventListener("click", () => {
if (source) {
document.location.reload();
} else {
loadVideo.textContent = "Reset example";
source = document.createElement("source");
source.setAttribute(
"src",
"https://mdn.github.io/learning-area/html/multimedia-and-embedding/video-and-audio-content/rabbit320.mp4",
);
source.setAttribute("type", "video/mp4");
video.appendChild(source);
}
});
結果
仕様書
Specification |
---|
HTML Standard # event-media-progress |
HTML Standard # handler-onprogress |
ブラウザーの互換性
BCD tables only load in the browser