Skip to content

Commit

Permalink
Update onProgress logic to still report loaded amounts when paused
Browse files Browse the repository at this point in the history
Fixes #94
Also serves as a better fix for #51
  • Loading branch information
cookpete committed Sep 24, 2016
1 parent 19a8f9c commit 060dbac
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/ReactPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 060dbac

Please sign in to comment.