Skip to content

Commit

Permalink
Ensure YouTube player calls onReady on subsequent loads
Browse files Browse the repository at this point in the history
Previously it would only call `onReady` after the initial load
Removes the need to pass `playing` through to `load()`, which is cleaner
  • Loading branch information
cookpete committed Jan 14, 2016
1 parent 8b31a8f commit 3a997bb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/players/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class Base extends Component {
componentWillReceiveProps (nextProps) {
// Invoke player methods based on incoming props
if (this.props.url !== nextProps.url && nextProps.url) {
this.load(nextProps.url, nextProps.playing)
this.load(nextProps.url)
this.seekOnReady = null
} else if (this.props.url && !nextProps.url) {
this.stop()
Expand Down Expand Up @@ -55,7 +55,7 @@ export default class Base extends Component {
if (this.props.playing || this.preloading) {
this.preloading = false
if (this.loadOnReady) {
this.load(this.loadOnReady, this.props.playing)
this.load(this.loadOnReady)
this.loadOnReady = null
} else {
this.play()
Expand Down
12 changes: 4 additions & 8 deletions src/players/YouTube.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,10 @@ export default class YouTube extends Base {
})
})
}
load (url, playing) {
load (url) {
const id = url && url.match(MATCH_URL)[1]
if (this.isReady) {
this.stop()
if (playing) {
this.player.loadVideoById(id)
} else {
this.player.cueVideoById(id)
}
this.player.cueVideoById(id)
return
}
if (this.loadingSDK) {
Expand Down Expand Up @@ -82,11 +77,12 @@ export default class YouTube extends Base {
})
}
onStateChange = ({ data }) => {
const { PLAYING, PAUSED, BUFFERING, ENDED } = window[SDK_GLOBAL].PlayerState
const { PLAYING, PAUSED, BUFFERING, ENDED, CUED } = window[SDK_GLOBAL].PlayerState
if (data === PLAYING) this.onPlay()
if (data === PAUSED) this.props.onPause()
if (data === BUFFERING) this.props.onBuffer()
if (data === ENDED) this.props.onEnded()
if (data === CUED) this.onReady()
};
play () {
if (!this.isReady || !this.player.playVideo) return
Expand Down

0 comments on commit 3a997bb

Please sign in to comment.