【发布时间】:2018-02-28 19:19:26
【问题描述】:
在调用 .play() 之前在 canplay 事件中设置 HTMLMediaElement 的 .currentTime 时,将调度 pause 事件。
在设置.currentTime 后尝试在canplay 事件中调用.play() 并引发错误
DOMException: The play() request was interrupted by a call to pause().
如何在HTMLMediaElement 的HTMLMediaElement 的canplay 或canplaythrough 事件中设置.currentTime 而不调度pause 事件,或者如何从pause 事件处理程序中调用.play() 以从该集合开始媒体播放.currentTime?
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<video preload="auto" controls></video>
<span></span>
<script>
const url = "https://mirrors.creativecommons.org/movingimages/webm/ScienceCommonsJesseDylan_240p.webm#t=10,15";
const video = document.querySelector("video");
let cursor = 10.5;
video.oncanplay = e => {
video.oncanplay = null;
video.currentTime = cursor;
console.log(e, video.currentTime, video.buffered.end(0));
video.play().catch(err => document.querySelector("span").textContent = err.message);
}
video.onpause = e => {
console.log(e, video.currentTime);
}
video.src = url;
</script>
</body>
</html>
【问题讨论】:
标签: javascript google-chrome html5-video html5-audio chromium