From ceeef6324eb2c7e98350f0995eb61725a4855ab2 Mon Sep 17 00:00:00 2001 From: akinwale Date: Sat, 19 May 2018 16:11:59 +0100 Subject: [PATCH] Video fullscreen switch (#132) * file page download progress display and media loading / playback tweaks * Moved MediaPlayer component to be a child of the top-level view * hide tracking controls when player controls are hidden in fullscreen mode --- app/src/component/mediaPlayer/view.js | 83 +++++++++++++++++++-------- app/src/page/file/view.js | 38 +++++++----- app/src/styles/filePage.js | 47 ++++++++------- app/src/styles/mediaPlayer.js | 37 ++++++++---- 4 files changed, 135 insertions(+), 70 deletions(-) diff --git a/app/src/component/mediaPlayer/view.js b/app/src/component/mediaPlayer/view.js index 1dd5f4b..2b74661 100644 --- a/app/src/component/mediaPlayer/view.js +++ b/app/src/component/mediaPlayer/view.js @@ -20,23 +20,30 @@ class MediaPlayer extends React.PureComponent { seekerWidth = 0; + trackingOffset = 0; + + tracking = null; + video = null; - state = { - rate: 1, - volume: 1, - muted: false, - resizeMode: 'stretch', - duration: 0.0, - currentTime: 0.0, - paused: true, - fullscreenMode: false, - areControlsVisible: true, - controlsTimeout: -1, - seekerOffset: 0, - seekerPosition: 0, - firstPlay: true - }; + constructor(props) { + super(props); + this.state = { + rate: 1, + volume: 1, + muted: false, + resizeMode: 'stretch', + duration: 0.0, + currentTime: 0.0, + paused: true, + fullscreenMode: false, + areControlsVisible: true, + controlsTimeout: -1, + seekerOffset: 0, + seekerPosition: 0, + firstPlay: true + }; + } formatTime(time) { let str = ''; @@ -144,10 +151,11 @@ class MediaPlayer extends React.PureComponent { } checkSeekerPosition(val = 0) { - if (val < 0) { - val = 0; - } else if (val >= this.seekerWidth) { - return this.seekerWidth; + const offset = this.getTrackingOffset(); + if (val < offset) { + val = offset; + } else if (val >= (offset + this.seekerWidth)) { + return offset + this.seekerWidth; } return val; @@ -190,11 +198,18 @@ class MediaPlayer extends React.PureComponent { }); } + getTrackingOffset() { + return this.state.fullscreenMode ? this.trackingOffset : 0; + } + getCurrentTimeForSeekerPosition() { return this.state.duration * (this.state.seekerPosition / this.seekerWidth); } calculateSeekerPosition() { + if (this.state.fullscreenMode) { + return this.getTrackingOffset() + (this.seekerWidth * this.getCurrentTimePercentage()); + } return this.seekerWidth * this.getCurrentTimePercentage(); } @@ -209,6 +224,10 @@ class MediaPlayer extends React.PureComponent { this.initSeeker(); } + componentDidMount() { + + } + componentWillUnmount() { this.clearControlsTimeout(); this.setState({ paused: true, fullscreenMode: false }); @@ -243,13 +262,23 @@ class MediaPlayer extends React.PureComponent { } render() { - const { backgroundPlayEnabled, fileInfo, thumbnail, style, fullScreenStyle } = this.props; + const { backgroundPlayEnabled, fileInfo, thumbnail, style } = this.props; const flexCompleted = this.getCurrentTimePercentage() * 100; const flexRemaining = (1 - this.getCurrentTimePercentage()) * 100; + let styles = [this.state.fullscreenMode ? mediaPlayerStyle.fullscreenContainer : mediaPlayerStyle.container]; + if (style) { + if (style.length) { + styles = styles.concat(style); + } else { + styles.push(style); + } + } + + const trackingStyle = [mediaPlayerStyle.trackingControls, this.state.fullscreenMode ? + mediaPlayerStyle.fullscreenTrackingControls : mediaPlayerStyle.containedTrackingControls]; return ( - - +