From e36ef24d27eaa52f1bb9fbe66cf5d52a58d58d4a Mon Sep 17 00:00:00 2001 From: webmiraclepro Date: Sat, 10 Sep 2016 12:01:25 +0800 Subject: [PATCH] Update onProgress logic to still report loaded amounts when paused Fixes https://github.com/CookPete/react-player/issues/94 Also serves as a better fix for https://github.com/CookPete/react-player/issues/51 --- src/ReactPlayer.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/ReactPlayer.js b/src/ReactPlayer.js index c59c27d..8f8ef6f 100644 --- a/src/ReactPlayer.js +++ b/src/ReactPlayer.js @@ -14,14 +14,6 @@ export default class ReactPlayer extends Component { componentDidMount () { this.progress() } - componentWillReceiveProps (nextProps) { - if (this.props.playing && !nextProps.playing) { - clearTimeout(this.progressTimeout) - } - if (!this.props.playing && nextProps.playing) { - this.progress() - } - } componentWillUnmount () { clearTimeout(this.progressTimeout) } @@ -45,11 +37,18 @@ export default class ReactPlayer extends Component { if (this.props.url && this.refs.player) { const loaded = this.refs.player.getFractionLoaded() || 0 const played = this.refs.player.getFractionPlayed() || 0 - if (loaded !== this.prevLoaded || played !== this.prevPlayed) { - this.props.onProgress({ loaded, played }) - this.prevLoaded = loaded - this.prevPlayed = played + const progress = {} + if (loaded !== this.prevLoaded) { + progress.loaded = loaded + } + if (played !== this.prevPlayed && this.props.playing) { + progress.played = played + } + if (progress.loaded || progress.playing) { + this.props.onProgress(progress) } + this.prevLoaded = loaded + this.prevPlayed = played } this.progressTimeout = setTimeout(this.progress, this.props.progressFrequency) }