Commit 48edd4a2 by Valera Rozuvan

Experimenting with optimal event attachment strategy.

parent a3a7d1d5
...@@ -83,6 +83,19 @@ class @VideoAlpha ...@@ -83,6 +83,19 @@ class @VideoAlpha
embed: -> embed: ->
@player = new VideoPlayerAlpha video: this @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) -> fetchMetadata: (url) ->
@metadata = {} @metadata = {}
$.each @videos, (speed, url) => $.each @videos, (speed, url) =>
...@@ -92,6 +105,15 @@ class @VideoAlpha ...@@ -92,6 +105,15 @@ class @VideoAlpha
@metadata[@youtubeId()].duration @metadata[@youtubeId()].duration
log: (eventName)-> log: (eventName)->
console.log 'log'
console.log 'this = ', this
console.log
id: @id
code: @youtubeId()
currentTime: @player.currentTime
speed: @speed
console.log ''
logInfo = logInfo =
id: @id id: @id
code: @youtubeId() code: @youtubeId()
......
...@@ -184,7 +184,6 @@ class @VideoPlayerAlpha extends SubviewAlpha ...@@ -184,7 +184,6 @@ class @VideoPlayerAlpha extends SubviewAlpha
@caption.pause() @caption.pause()
onPlay: => onPlay: =>
@video.log 'play_video'
unless @player.interval unless @player.interval
@player.interval = setInterval(@update, 200) @player.interval = setInterval(@update, 200)
if @video.show_captions is true if @video.show_captions is true
...@@ -193,7 +192,6 @@ class @VideoPlayerAlpha extends SubviewAlpha ...@@ -193,7 +192,6 @@ class @VideoPlayerAlpha extends SubviewAlpha
@progressSlider.play() @progressSlider.play()
onPause: => onPause: =>
@video.log 'pause_video'
clearInterval(@player.interval) clearInterval(@player.interval)
@player.interval = null @player.interval = null
if @video.show_captions is true if @video.show_captions is true
...@@ -206,6 +204,7 @@ class @VideoPlayerAlpha extends SubviewAlpha ...@@ -206,6 +204,7 @@ class @VideoPlayerAlpha extends SubviewAlpha
@caption.pause() @caption.pause()
onSeek: (event, time) => onSeek: (event, time) =>
console.log 'old time = ' + @currentTime + ', new time = ' + time
@player.seekTo(time, true) @player.seekTo(time, true)
if @isPlaying() if @isPlaying()
clearInterval(@player.interval) clearInterval(@player.interval)
......
...@@ -6,7 +6,11 @@ class @VideoProgressSliderAlpha extends SubviewAlpha ...@@ -6,7 +6,11 @@ class @VideoProgressSliderAlpha extends SubviewAlpha
@slider = @el.slider @slider = @el.slider
range: 'min' range: 'min'
change: @onChange 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 stop: @onStop
@buildHandle() @buildHandle()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment