Skip to content

Commit

Permalink
Prevent errors when switching URLs whilst loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Webmaster1116 committed May 15, 2018
1 parent 9fb5c9e commit 46072be
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Player.js
Expand Up @@ -12,6 +12,7 @@ export default class Player extends Component {
isReady = false
isPlaying = false // Track playing state internally to prevent bugs
isLoading = true // Use isLoading to prevent onPause when switching URL
loadOnReady = null
startOnPlay = true
seekOnPlay = null
onDurationCalled = false
Expand All @@ -32,6 +33,11 @@ export default class Player extends Component {
// Invoke player methods based on incoming props
const { url, playing, volume, muted, playbackRate } = this.props
if (url !== nextProps.url) {
if (this.isLoading) {
console.warn(`ReactPlayer: the attempt to load ${nextProps.url} is being deferred until the player has loaded`)
this.loadOnReady = nextProps.url
return
}
this.isLoading = true
this.startOnPlay = true
this.onDurationCalled = false
Expand Down Expand Up @@ -131,7 +137,10 @@ export default class Player extends Component {
if (!muted && volume !== null) {
this.player.setVolume(volume)
}
if (playing) {
if (this.loadOnReady) {
this.player.load(this.loadOnReady, true)
this.loadOnReady = null
} else if (playing) {
this.player.play()
}
this.onDurationCheck()
Expand Down

0 comments on commit 46072be

Please sign in to comment.