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 cookpete/react-player#52
  • Loading branch information
albanqoku committed Jun 1, 2016
1 parent 7c26a29 commit 031fdd3
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 031fdd3

Please sign in to comment.