HTMLMediaElement: progress event - Web APIs 编辑
The progress
event is fired periodically as the browser loads a resource.
Bubbles | No |
---|---|
Cancelable | No |
Interface | Event |
Event handler property | onprogress |
Examples
Live example
HTML
<div class="example">
<button type="button">Load video</button>
<video controls width="250"></video>
<div class="event-log">
<label>Event log:</label>
<textarea readonly class="event-log-contents"></textarea>
</div>
</div>
CSS
.event-log-contents {
width: 18rem;
height: 5rem;
border: 1px solid black;
margin: .2rem;
padding: .2rem;
}
.example {
display: grid;
grid-template-areas:
"button log"
"video log";
}
button {
grid-area: button;
width: 10rem;
margin: .5rem 0;
}
video {
grid-area: video;
}
.event-log {
grid-area: log;
}
.event-log>label {
display: block;
}
JavaScript
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 = 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);
}
});
Result
Specifications
Specification | Status |
---|---|
HTML Living Standard The definition of 'progress media event' in that specification. | Living Standard |
HTML5 The definition of 'progress media event' in that specification. | Recommendation |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论