From d46d47ee9c79dce950bd149c4c5097476e6ce060 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 29 Oct 2020 17:30:22 +0100 Subject: getting scrubber working with the new start ts --- .../player/components.media/video.scrubber.js | 29 ++++++++++++++++------ 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'animism-align/frontend/app/views/viewer/player/components.media') diff --git a/animism-align/frontend/app/views/viewer/player/components.media/video.scrubber.js b/animism-align/frontend/app/views/viewer/player/components.media/video.scrubber.js index 01255f6..bb6a753 100644 --- a/animism-align/frontend/app/views/viewer/player/components.media/video.scrubber.js +++ b/animism-align/frontend/app/views/viewer/player/components.media/video.scrubber.js @@ -43,14 +43,22 @@ class VideoScrubber extends Component { this.setState({ showing: false }) } scrub(x, scrubbing) { - const { timing, start_ts, onScrub, duration } = this.props + const { timing, start_ts, video_start_ts, onScrub, duration } = this.props const bounds = this.scrubberRef.current.getBoundingClientRect() + // get percent offset from the scrubber const percent = clamp((x - bounds.left) / bounds.width, 0, 1) + // this offset in seconds based on the length of the fullscreen element const seconds = percent * duration + // we can use this to seek the audio actions.audio.seek(start_ts + seconds) + // apply the video start offset. + // in case the video loops, modulo the length of the original video + const video_seek = ((seconds + video_start_ts) % timing.duration) + // onScrub({ - seek: seconds % timing.duration, - percent, seconds, scrubbing + seek: video_seek, + seconds: video_seek, + scrubbing, }) } handleMouseDown(e) { @@ -74,10 +82,17 @@ class VideoScrubber extends Component { this.setState({ hovering: false }) } render() { - const { playing, volume, timing, duration } = this.props + const { playing, volume, timing, video_start_ts, duration } = this.props const { hovering, showing } = this.state - const timestampText = timestamp(clamp(timing.seconds, 0, duration)) + // remove video start offset from timing + const player_ts = timing.seconds - video_start_ts + // compute percent from the length of the fullscreen element + const percent = player_ts / duration + // display timestamp from the fullscreen element too + const timestampText = timestamp(clamp(player_ts, 0, duration)) + // show or hide the scrubber bar const className = (hovering || showing) ? 'video-scrubber show' : 'video-scrubber' + // console.log(timing.seconds, video_start_ts, duration) return (
@@ -93,11 +108,11 @@ class VideoScrubber extends Component {
{timestampText}
-- cgit v1.2.3-70-g09d2