Skip to content

Commit

Permalink
Handle YouTube URL change during SDK load
Browse files Browse the repository at this point in the history
  • Loading branch information
philip-luther committed Nov 22, 2024
1 parent bb7d450 commit 3bafcc7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/players/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
}
10 changes: 9 additions & 1 deletion src/players/YouTube.js
Original file line number Diff line number Diff line change
Expand Up @@ -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%',
Expand All @@ -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
}
Expand Down

0 comments on commit 3bafcc7

Please sign in to comment.