Experimenting with optimal event attachment strategy.
This commit is contained in:
@@ -83,6 +83,19 @@ class @VideoAlpha
|
||||
embed: ->
|
||||
@player = new VideoPlayerAlpha video: this
|
||||
|
||||
@attachEventDispatchToFunctions
|
||||
onPlay: 'play_video'
|
||||
onPause: 'pause_video'
|
||||
|
||||
attachEventDispatchToFunctions: (funcList) ->
|
||||
$.each funcList, (funcName, eventName) =>
|
||||
@player[funcName] = @attachEventDispatch(@player[funcName], eventName) if @player.hasOwnProperty(funcName)
|
||||
|
||||
attachEventDispatch: (func, eventName) ->
|
||||
=>
|
||||
@log eventName
|
||||
func.apply this, arguments
|
||||
|
||||
fetchMetadata: (url) ->
|
||||
@metadata = {}
|
||||
$.each @videos, (speed, url) =>
|
||||
@@ -92,6 +105,15 @@ class @VideoAlpha
|
||||
@metadata[@youtubeId()].duration
|
||||
|
||||
log: (eventName)->
|
||||
console.log 'log'
|
||||
console.log 'this = ', this
|
||||
console.log
|
||||
id: @id
|
||||
code: @youtubeId()
|
||||
currentTime: @player.currentTime
|
||||
speed: @speed
|
||||
console.log ''
|
||||
|
||||
logInfo =
|
||||
id: @id
|
||||
code: @youtubeId()
|
||||
|
||||
@@ -184,7 +184,6 @@ class @VideoPlayerAlpha extends SubviewAlpha
|
||||
@caption.pause()
|
||||
|
||||
onPlay: =>
|
||||
@video.log 'play_video'
|
||||
unless @player.interval
|
||||
@player.interval = setInterval(@update, 200)
|
||||
if @video.show_captions is true
|
||||
@@ -193,7 +192,6 @@ class @VideoPlayerAlpha extends SubviewAlpha
|
||||
@progressSlider.play()
|
||||
|
||||
onPause: =>
|
||||
@video.log 'pause_video'
|
||||
clearInterval(@player.interval)
|
||||
@player.interval = null
|
||||
if @video.show_captions is true
|
||||
@@ -206,6 +204,7 @@ class @VideoPlayerAlpha extends SubviewAlpha
|
||||
@caption.pause()
|
||||
|
||||
onSeek: (event, time) =>
|
||||
console.log 'old time = ' + @currentTime + ', new time = ' + time
|
||||
@player.seekTo(time, true)
|
||||
if @isPlaying()
|
||||
clearInterval(@player.interval)
|
||||
|
||||
@@ -6,7 +6,11 @@ class @VideoProgressSliderAlpha extends SubviewAlpha
|
||||
@slider = @el.slider
|
||||
range: 'min'
|
||||
change: @onChange
|
||||
slide: @onSlide
|
||||
|
||||
# We don't want to attach to 'slide' event because we already have 'change' event.
|
||||
# If we have two events, then callback will be triggered twice, sending misinformation
|
||||
# to the server.
|
||||
# slide: @onSlide
|
||||
stop: @onStop
|
||||
@buildHandle()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user