From fea78c046c196c3082b4c021555339583bcaf47b Mon Sep 17 00:00:00 2001 From: Pete Cook Date: Wed, 1 Jun 2016 16:46:02 +0100 Subject: [PATCH] Fix onDuration being called with null 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 https://github.com/CookPete/react-player/issues/52 --- src/players/Base.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/players/Base.js b/src/players/Base.js index d6ad6905..c1803125 100644 --- a/src/players/Base.js +++ b/src/players/Base.js @@ -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) @@ -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 @@ -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) {