JSFiddle - React, Tailwind, and code Playground
HTML
<video width="480" height="400" controls="true" poster="">
<source type="video/mp4" src="https://sample-videos.com/video123/mp4/240/big_buck_bunny_240p_2mb.mp4" />
</video>
JavaScript
const $video = document.querySelector("video");
const onTimeUpdate = event => {
console.log(checkSkipped(event.target.currentTime));
}
let prevTime = 0;
const checkSkipped = currentTime => {
const skip = [];
const skipThershold = 2;
// user skipped any part of the video
if (currentTime - prevTime > skipThershold) {
skip.push({
periodSkipped: currentTime - prevTime,
startAt: prevTime,
endAt: currentTime,
});
prevTime = currentTime;
return skip;
}
prevTime = currentTime;
return false;
}
$video.addEventListener("play", e => console.log('play'));
$video.addEventListener("playing", e => console.log('playing'));
$video.addEventListener("timeupdate", onTimeUpdate);
$video.addEventListener("ended", e => console.log('ended'));
$video.addEventListener("pause", e => console.log('pause'));