Skip to content

Commit

Permalink
Stronger guards for YouTube player methods
Browse files Browse the repository at this point in the history
Still a bit strange that this can still happen, but this prevents errors for now
  • Loading branch information
cookpete committed Jan 2, 2016
1 parent 900b381 commit f18792a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/players/YouTube.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,31 @@ export default class YouTube extends Base {
if (state.data === YT.PlayerState.ENDED) this.props.onEnded()
}
play () {
if (!this.isReady) return
if (!this.isReady || !this.player.playVideo) return
this.player.playVideo()
}
pause () {
if (!this.isReady) return
if (!this.isReady || this.player.pauseVideo) return
this.player.pauseVideo()
}
stop () {
if (!this.isReady) return
if (!this.isReady || !this.player.stopVideo) return
this.player.stopVideo()
}
seekTo (fraction) {
if (!this.isReady) return
if (!this.isReady || !this.player.seekTo) return
this.player.seekTo(this.player.getDuration() * fraction)
}
setVolume (fraction) {
if (!this.isReady) return
if (!this.isReady || !this.player.setVolume) return
this.player.setVolume(fraction * 100)
}
getFractionPlayed () {
if (!this.isReady) return null
if (!this.isReady || !this.player.getCurrentTime) return null
return this.player.getCurrentTime() / this.player.getDuration()
}
getFractionLoaded () {
if (!this.isReady) return null
if (!this.isReady || !this.player.getVideoLoadedFraction) return null
return this.player.getVideoLoadedFraction()
}
render () {
Expand Down

0 comments on commit f18792a

Please sign in to comment.