views:

34

answers:

2

I'm trying to get a basic function to execute when an HTML5 video reaches a specific second value. Currently I haven't had any luck and was hoping that I could get some help here. Here's the code I'm using thus far:

jQuery(function(){
    jQuery("video").bind("timeupdate", function() {
        if(this.currentTime == "6") { alert("six seconds in"); }
        // also tried the above line with the 6 not in quotes
    });
});

I just want to do a really basic content swap around the video but am not having much luck thus far. Thanks in advance for any help!

A: 

This vanilla JavaScript works just fine for me:

video.addEventListener('timeupdate', function(e) {
    if (e.target.currentTime == 6) ...
}, false);
Delan Azabani
+1  A: 

currentTime is a float value, not an integer. Remove the fractional part for the comparison.

var currentTime = parseInt(this.currentTime, 10);
if(currentTime == 6) { 
    ..
}
Anurag
Worked like a charm, thanks!
Andrew