|
|
@ -7,37 +7,35 @@
|
|
|
|
let showControls = true;
|
|
|
|
let showControls = true;
|
|
|
|
let showControlsTimeout;
|
|
|
|
let showControlsTimeout;
|
|
|
|
|
|
|
|
|
|
|
|
function handleMousemove(e) {
|
|
|
|
// Used to track time of last mouse down event
|
|
|
|
|
|
|
|
let lastMouseDown;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function handleMove(e) {
|
|
|
|
// Make the controls visible, but fade out after
|
|
|
|
// Make the controls visible, but fade out after
|
|
|
|
// 2.5 seconds of inactivity
|
|
|
|
// 2.5 seconds of inactivity
|
|
|
|
clearTimeout(showControlsTimeout);
|
|
|
|
clearTimeout(showControlsTimeout);
|
|
|
|
showControlsTimeout = setTimeout(() => showControls = false, 2500);
|
|
|
|
showControlsTimeout = setTimeout(() => showControls = false, 2500);
|
|
|
|
showControls = true;
|
|
|
|
showControls = true;
|
|
|
|
|
|
|
|
|
|
|
|
if (!(e.buttons & 1)) return; // mouse not down
|
|
|
|
|
|
|
|
if (!duration) return; // video not loaded yet
|
|
|
|
if (!duration) return; // video not loaded yet
|
|
|
|
|
|
|
|
if (e.type !== 'touchmove' && !(e.buttons & 1)) return; // mouse not down
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const clientX = e.type === 'touchmove' ? e.touches[0].clientX : e.clientX;
|
|
|
|
const { left, right } = this.getBoundingClientRect();
|
|
|
|
const { left, right } = this.getBoundingClientRect();
|
|
|
|
time = duration * (e.clientX - left) / (right - left);
|
|
|
|
time = duration * (clientX - left) / (right - left);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// we can't rely on the built-in click event, because it fires
|
|
|
|
|
|
|
|
// after a drag — we have to listen for clicks ourselves
|
|
|
|
function handleMousedown(e) {
|
|
|
|
function handleMousedown(e) {
|
|
|
|
// we can't rely on the built-in click event, because it fires
|
|
|
|
lastMouseDown = new Date();
|
|
|
|
// after a drag — we have to listen for clicks ourselves
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function handleMouseup() {
|
|
|
|
function handleMouseup(e) {
|
|
|
|
|
|
|
|
if (new Date() - lastMouseDown < 300) {
|
|
|
|
if (paused) e.target.play();
|
|
|
|
if (paused) e.target.play();
|
|
|
|
else e.target.pause();
|
|
|
|
else e.target.pause();
|
|
|
|
cancel();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function cancel() {
|
|
|
|
|
|
|
|
e.target.removeEventListener('mouseup', handleMouseup);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
e.target.addEventListener('mouseup', handleMouseup);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setTimeout(cancel, 200);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function format(seconds) {
|
|
|
|
function format(seconds) {
|
|
|
@ -58,8 +56,10 @@
|
|
|
|
<video
|
|
|
|
<video
|
|
|
|
poster="https://sveltejs.github.io/assets/caminandes-llamigos.jpg"
|
|
|
|
poster="https://sveltejs.github.io/assets/caminandes-llamigos.jpg"
|
|
|
|
src="https://sveltejs.github.io/assets/caminandes-llamigos.mp4"
|
|
|
|
src="https://sveltejs.github.io/assets/caminandes-llamigos.mp4"
|
|
|
|
on:mousemove={handleMousemove}
|
|
|
|
on:mousemove={handleMove}
|
|
|
|
on:mousedown={handleMousedown}>
|
|
|
|
on:touchmove|preventDefault={handleMove}
|
|
|
|
|
|
|
|
on:mousedown={handleMousedown}
|
|
|
|
|
|
|
|
on:mouseup={handleMouseup}>
|
|
|
|
<track kind="captions">
|
|
|
|
<track kind="captions">
|
|
|
|
</video>
|
|
|
|
</video>
|
|
|
|
|
|
|
|
|
|
|
@ -125,4 +125,4 @@
|
|
|
|
video {
|
|
|
|
video {
|
|
|
|
width: 100%;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</style>
|
|
|
|