From 5e4b9365a5f71827aafd674f97464441707c5d3c Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 22 Sep 2020 16:32:35 +0200 Subject: scrub bar --- .../components.fullscreen/fullscreen.video.js | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'animism-align/frontend/app/views/viewer/player/components.fullscreen') diff --git a/animism-align/frontend/app/views/viewer/player/components.fullscreen/fullscreen.video.js b/animism-align/frontend/app/views/viewer/player/components.fullscreen/fullscreen.video.js index e9586b6..d6f95ed 100644 --- a/animism-align/frontend/app/views/viewer/player/components.fullscreen/fullscreen.video.js +++ b/animism-align/frontend/app/views/viewer/player/components.fullscreen/fullscreen.video.js @@ -11,13 +11,28 @@ class FullscreenVideo extends Component { percent: 0.0, seconds: 0.0, seek: 0.0, + scrubbing: false, } constructor(props) { super(props) + this.scrubberRef = React.createRef() this.handlePlay = this.handlePlay.bind(this) this.handlePause = this.handlePause.bind(this) this.handleTimeUpdate = this.handleTimeUpdate.bind(this) this.handleEnd = this.handleEnd.bind(this) + this.handleScrubBarClick = this.handleScrubBarClick.bind(this) + this.handleScrubDotMouseDown = this.handleScrubDotMouseDown.bind(this) + this.handleScrubDotMouseMove = this.handleScrubDotMouseMove.bind(this) + this.handleScrubDotMouseUp = this.handleScrubDotMouseUp.bind(this) + } + componentDidMount() { + window.addEventListener('mousemove', this.handleScrubDotMouseMove) + window.addEventListener('mouseup', this.handleScrubDotMouseUp) + } + componentWillUnmount() { + window.removeEventListener('mousemove', this.handleScrubDotMouseMove) + window.removeEventListener('mouseup', this.handleScrubDotMouseUp) + this.setState({ scrubbing: false }) } componentDidUpdate(prevProps) { if (Math.abs(this.props.play_ts - prevProps.play_ts) > 2.0) { @@ -38,6 +53,27 @@ class FullscreenVideo extends Component { handleTimeUpdate(timing) { this.setState(timing) } + handleScrubBarClick(e) { + e.stopPropagation() + const bounds = this.scrubberRef.current.getBoundingClientRect() + const percent = (e.pageX - bounds.left) / bounds.width + const seconds = percent * this.state.duration + actions.audio.seek(this.props.element.start_ts + seconds) + this.setState({ percent, seconds }) + // actions.audio.seek(clamp(play_ts - 5.0, start_ts, end_ts)) + } + handleScrubDotMouseDown(e) { + e.stopPropagation() + this.setState({ scrubbing: true }) + } + handleScrubDotMouseMove(e) { + e.stopPropagation() + if (!this.state.scrubbing) return + } + handleScrubDotMouseUp(e) { + e.stopPropagation() + this.setState({ scrubbing: false }) + } render() { const { element, media, transitionDuration, playing, volume } = this.props const { duration, percent, seconds } = this.state @@ -70,6 +106,18 @@ class FullscreenVideo extends Component { onEnd={this.handleEnd} /> +
+
+
+
actions.viewer.toggleComponent('nav')}> {item.title} -- cgit v1.2.3-70-g09d2