Skip to content

Commit

Permalink
Fix onDuration being called with null
Browse files Browse the repository at this point in the history
Some players need onDuration to be called onReady (FilePlayer) and some need it onPlay (YouTube)
Instead of spreading onDuration amongst individual player files, here we just delay onDuration until onPlay if it returns null when onReady fires
Fixes #52
  • Loading branch information
cookpete committed Jun 1, 2016
1 parent 564243e commit fea78c0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/players/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default class Base extends Component {
static defaultProps = defaultProps
isReady = false
startOnPlay = true
durationOnPlay = false
componentDidMount () {
if (this.props.url) {
this.load(this.props.url)
Expand Down Expand Up @@ -55,7 +56,10 @@ export default class Base extends Component {
this.seekTo(this.seekOnReady)
this.seekOnReady = null
}
this.props.onDuration(this.getDuration())
if (this.durationOnPlay) {
this.props.onDuration(this.getDuration())
this.durationOnPlay = false
}
}
onReady = () => {
this.isReady = true
Expand All @@ -68,6 +72,12 @@ export default class Base extends Component {
this.play()
}
}
const duration = this.getDuration()
if (duration) {
this.props.onDuration(duration)
} else {
this.durationOnPlay = true
}
}
onEnded = () => {
if (this.props.loop) {
Expand Down

0 comments on commit fea78c0

Please sign in to comment.