Skip to content

Commit

Permalink
feat: experimental double tap skipping for videos
Browse files Browse the repository at this point in the history
  • Loading branch information
kurozenzen committed May 29, 2023
1 parent ef52e9a commit 8664e74
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/lib/player/Player.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,23 @@
const dispatch = createEventDispatcher()
const dispatchClick = () => dispatch('click')
const skipBackward = () => {
currentTime = Math.max(0, currentTime - SKIP_TIME)
}
const skipForward = () => {
currentTime = Math.min(duration, currentTime + SKIP_TIME)
}
/** @type {(event: KeyboardEvent) => void} */
const handleKeyDown = (event) => {
if (isEnter(event)) {
dispatchClick()
} else if (event.key === ' ') {
playing = !playing
} else if (event.key === 'ArrowLeft') {
currentTime = Math.max(0, currentTime - SKIP_TIME)
skipBackward()
} else if (event.key === 'ArrowRight') {
currentTime = Math.min(duration, currentTime + SKIP_TIME)
skipForward()
}
}
Expand Down Expand Up @@ -126,6 +133,13 @@
playing = false
}
}}
on:dblclick|stopPropagation|preventDefault={(event) => {
if (event.offsetX < event.target.clientWidth / 2) {
skipBackward()
} else {
skipForward()
}
}}
preload="metadata"
style={`aspect-ratio: ${width} / ${height}`}
/>
Expand All @@ -138,7 +152,7 @@
max={duration}
step={0.0166666}
class:hide={hideOverlay}
style={`background-image: linear-gradient(90deg, var(--accent) ${percent}%, var(--background-2) ${percent}%);`}}
style="{`background-image: linear-gradient(90deg, var(--accent) ${percent}%, var(--background-2) ${percent}%);`}}"
/>
<PlayButton bind:playing bind:loading class="center" />
{/if}
Expand Down

0 comments on commit 8664e74

Please sign in to comment.