Fixes
This commit is contained in:
parent
391ea264f5
commit
d7b69bce38
4 changed files with 38 additions and 33 deletions
|
|
@ -4,12 +4,10 @@ TYPE_MAP =
|
|||
|
||||
window.loadMediaPlayer = (data) ->
|
||||
if data.type of TYPE_MAP
|
||||
console.log data
|
||||
try
|
||||
window.PLAYER = TYPE_MAP[data.type](data)
|
||||
catch e
|
||||
console.error e
|
||||
console.log(window.PLAYER)
|
||||
|
||||
window.handleMediaUpdate = (data) ->
|
||||
PLAYER = window.PLAYER
|
||||
|
|
@ -33,6 +31,7 @@ window.handleMediaUpdate = (data) ->
|
|||
PLAYER.play()
|
||||
|
||||
if waiting
|
||||
PLAYER.seekTo(0)
|
||||
# YouTube player has a race condition that crashes the player if
|
||||
# play(), seek(0), and pause() are called quickly without waiting
|
||||
# for events to fire. Setting a flag variable that is checked in the
|
||||
|
|
@ -40,8 +39,8 @@ window.handleMediaUpdate = (data) ->
|
|||
if PLAYER instanceof YouTubePlayer
|
||||
PLAYER.pauseSeekRaceCondition = true
|
||||
else
|
||||
PLAYER.seekTo(0)
|
||||
PLAYER.pause()
|
||||
return
|
||||
else if PLAYER instanceof YouTubePlayer
|
||||
PLAYER.pauseSeekRaceCondition = false
|
||||
|
||||
|
|
|
|||
|
|
@ -28,13 +28,16 @@ window.YouTubePlayer = class YouTubePlayer extends Player
|
|||
|
||||
load: (data) ->
|
||||
@setMediaProperties(data)
|
||||
if @yt
|
||||
if @yt and @yt.ready
|
||||
@yt.loadVideoById(data.id, data.currentTime)
|
||||
@qualityRaceCondition = true
|
||||
if USEROPTS.default_quality
|
||||
@yt.setPlaybackQuality(USEROPTS.default_quality)
|
||||
else
|
||||
console.error('WTF? YouTubePlayer::load() called but yt is not ready')
|
||||
|
||||
onReady: ->
|
||||
@yt.ready = true
|
||||
@setVolume(VOLUME)
|
||||
|
||||
onStateChange: (ev) ->
|
||||
|
|
@ -62,20 +65,20 @@ window.YouTubePlayer = class YouTubePlayer extends Player
|
|||
|
||||
play: ->
|
||||
@paused = false
|
||||
if @yt
|
||||
if @yt and @yt.ready
|
||||
@yt.playVideo()
|
||||
|
||||
pause: ->
|
||||
@paused = true
|
||||
if @yt
|
||||
if @yt and @yt.ready
|
||||
@yt.pauseVideo()
|
||||
|
||||
seekTo: (time) ->
|
||||
if @yt
|
||||
if @yt and @yt.ready
|
||||
@yt.seekTo(time, true)
|
||||
|
||||
setVolume: (volume) ->
|
||||
if @yt
|
||||
if @yt and @yt.ready
|
||||
if volume > 0
|
||||
# If the player is muted, even if the volume is set,
|
||||
# the player remains muted
|
||||
|
|
@ -83,13 +86,13 @@ window.YouTubePlayer = class YouTubePlayer extends Player
|
|||
@yt.setVolume(volume * 100)
|
||||
|
||||
getTime: (cb) ->
|
||||
if @yt
|
||||
if @yt and @yt.ready
|
||||
cb(@yt.getCurrentTime())
|
||||
else
|
||||
cb(0)
|
||||
|
||||
getVolume: (cb) ->
|
||||
if @yt
|
||||
if @yt and @yt.ready
|
||||
if @yt.isMuted()
|
||||
cb(0)
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue