Last active
April 11, 2016 13:06
-
-
Save dpmccabe/5456279 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class @VideoProgressTracker | |
constructor: (@video) -> | |
@played_five_seconds = 0 | |
@checkpoints = [0, 25, 50, 75, 95] | |
track: -> | |
@played_five_seconds += 1 | |
@triggerCheckpoints(500 * @played_five_seconds / @duration) | |
start: -> | |
@duration ?= @video.getDuration() | |
clearInterval(@interval) | |
@setUpdateInterval() | |
pause: -> | |
clearInterval(@interval) | |
setUpdateInterval: -> | |
callback = => @track() | |
@interval = setInterval callback, 5000 | |
triggerCheckpoints: (current_percent) -> | |
if current_percent >= @checkpoints[0] | |
completed_percent = @checkpoints.shift() | |
$.post(gon.record_video_progress_path, { lesson_id: gon.lesson_id, percent: completed_percent }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jwplayer("video").setup | |
events: | |
onPlay: (e) -> | |
video_tracker.start() | |
onPause: (e) -> | |
video_tracker.pause() | |
@.video_tracker = new VideoProgressTracker(jwplayer("video")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment