When setting .currentTime
of HTMLMediaElement
within canplay
event before calling .play()
the pause
event is dispatched.
When trying to call .play()
within canplay
event after setting .currentTime
and error is thrown
DOMException: The play() request was interrupted by a call to pause().
How to set .currentTime
within canplay
or canplaythrough
event of HTMLMediaElement
without dispatching pause
event, or how to call .play()
from within pause
event handler to commence media playback from the set .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>