Skip to content

Commit

Permalink
Refactor onDuration logic
Browse files Browse the repository at this point in the history
  • Loading branch information
cookpete committed Sep 9, 2017
1 parent 4551f25 commit 31c1dac
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/players/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export default class Base extends Component {
static defaultProps = defaultProps
isReady = false
startOnPlay = true
durationOnPlay = false
seekOnPlay = null
componentDidMount () {
const { url } = this.props
Expand Down Expand Up @@ -63,7 +62,7 @@ export default class Base extends Component {
return amount
}
onPlay = () => {
const { volume, muted, onStart, onPlay, onDuration, playbackRate } = this.props
const { volume, muted, onStart, onPlay, playbackRate } = this.props
if (this.startOnPlay) {
this.setPlaybackRate(playbackRate)
this.setVolume(muted ? 0 : volume)
Expand All @@ -75,13 +74,10 @@ export default class Base extends Component {
this.seekTo(this.seekOnPlay)
this.seekOnPlay = null
}
if (this.durationOnPlay) {
onDuration(this.getDuration())
this.durationOnPlay = false
}
this.onDurationCheck()
}
onReady = () => {
const { onReady, playing, onDuration } = this.props
const { onReady, playing } = this.props
this.isReady = true
this.loadingSDK = false
onReady()
Expand All @@ -94,11 +90,15 @@ export default class Base extends Component {
this.play()
}
}
this.onDurationCheck()
}
onDurationCheck = () => {
clearTimeout(this.durationCheckTimeout)
const duration = this.getDuration()
if (duration) {
onDuration(duration)
this.props.onDuration(duration)
} else {
this.durationOnPlay = true
this.durationCheckTimeout = setTimeout(this.onDurationCheck, 100)
}
}
}

0 comments on commit 31c1dac

Please sign in to comment.