From 3bafcc7259668e6248e41b91529b34086acf5155 Mon Sep 17 00:00:00 2001 From: philip-luther Date: Sun, 3 Jan 2016 10:11:09 +0000 Subject: [PATCH] Handle YouTube URL change during SDK load Fixes https://github.com/CookPete/react-player/issues/20 --- src/players/Base.js | 6 +++++- src/players/YouTube.js | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/players/Base.js b/src/players/Base.js index 694af1e..f49d16a 100644 --- a/src/players/Base.js +++ b/src/players/Base.js @@ -38,7 +38,11 @@ export default class Base extends Component { if (this.props.playing || this.preloading) { this.preloading = false this.isReady = true - this.play() + if (this.loadOnReady) { + this.load(this.loadOnReady, this.props.playing) + } else { + this.play() + } } } } diff --git a/src/players/YouTube.js b/src/players/YouTube.js index b90a5e3..32ecfc2 100644 --- a/src/players/YouTube.js +++ b/src/players/YouTube.js @@ -56,6 +56,11 @@ export default class YouTube extends Base { } return } + if (this.loadingSDK) { + this.loadOnReady = url + return + } + this.loadingSDK = true this.getSDK().then(YT => { this.player = new YT.Player(this.playerId, { width: '100%', @@ -66,7 +71,10 @@ export default class YouTube extends Base { ...this.props.youtubeConfig.playerVars }, events: { - onReady: this.onReady, + onReady: () => { + this.loadingSDK = false + this.onReady() + }, onStateChange: this.onStateChange, onError: this.props.onError }