Skip to content

Instantly share code, notes, and snippets.

@staydecent
Created April 4, 2011 20:38
Show Gist options
  • Save staydecent/902380 to your computer and use it in GitHub Desktop.
Save staydecent/902380 to your computer and use it in GitHub Desktop.
video timelime events, lzimm halp mez
jQuery(document).ready(function($) {
var video = $('.video');
var vCount = 0; // Or own counter, for counting
var chapters = {
// seconds : selector
// I forget what data types JS has.... LOLZ
// Pythonz in my brain
1 : 'one-second'
}
video.bind('timeupdate', function(o) {
// as a video is playing, event is triggered as it moves along
// we don't like decimals
var currentSeconds = parseInt(video.attr('currentTime'));
if (currentSeconds >= vCount) {
console.log(vCount);
// so here we should check if we want to do a 'chapters' event
// which would be animating the selector
// wishing on smth more elegant than bunch of hard ifs
vCount = vCount + 1;
}
});
});
@staydecent
Copy link
Author

Yeah that's to prevent it from firing(console.log) more than once per second. timeupdate is more specific than just seconds (0.1782312).

@lzimm
Copy link

lzimm commented Apr 4, 2011

ahhh, first thing to be aware if is if you can jump around the timeline there's miscoordination gonna happen there right? like, vCount = 55, time=55.11512... scrub back to time=3, not gonna fire for 52 seconds now, dunno if that's an issue though.

but to your actual matter, you can do something hacky like setInterval(function() { console.log(GLOBAL_LOG_LINE); }, 1000); then every frame just set GLOBAL_LOG_LINE, otherwise though, your solution should be fine, though parseInt gonna kinda suck, maybe do str comparison or something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment