From 0716444be55eada47634a1c4a9ebab64a0809558 Mon Sep 17 00:00:00 2001 From: David Ernst Date: Fri, 1 May 2020 21:57:42 -0700 Subject: [PATCH] Working video scrubbing preview --- src/renderer/pages/player-page.js | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/renderer/pages/player-page.js b/src/renderer/pages/player-page.js index a981837b..783dfaf5 100644 --- a/src/renderer/pages/player-page.js +++ b/src/renderer/pages/player-page.js @@ -549,7 +549,7 @@ function renderPlayerControls (state) { key='scrub-bar' className='scrub-bar' draggable - onMouseOver={handleScrubPreview} + onMouseMove={handleScrubPreview} onMouseOut={clearPreview} onDragStart={handleDragStart} onClick={handleScrub} @@ -779,18 +779,32 @@ function renderPlayerControls (state) { } function renderPreview (state) { - if (!state.playing.preview) { - return null + let { preview } = state.playing + if (!preview) { + preview = { x: 0, time: 0, hide: true } } - const width = 118 + const height = 70 + let width - const xPos = Math.max(state.playing.preview.x - (width / 2), 5) + const previewEl = document.querySelector('video#preview') + if (previewEl !== null && !preview.hide) { + previewEl.currentTime = preview.time + width = (previewEl.videoWidth / previewEl.videoHeight) * height + } + + const windowWidth = document.querySelector('body').clientWidth + const xPos = Math.min(Math.max(preview.x - (width / 2), 5), windowWidth - width - 5) return ( -
-
-

{formatTime(state.playing.preview.time, state.playing.duration)}

+
+
+
+

{formatTime(preview.time, state.playing.duration)}

) }