I am coding a web page that has an embedded jPlayer. The player has a timeupdate attribute that allows you to call a function whenever the time updates (at approximately 4 Hz). I have it calling a function that updates an interactive transcript on the page, that highlights what is currently being said using json data that has timecodes associated with the various parts of the transcript. The function also returns json data to be used the next time it is run, so it can keep track of where it is without having to search the entire json file every time.
Everything works great except one condition that never triggers, where it seemingly should. If the current time is more than 0.75 seconds different than the last time, then I should assume that the user clicked back or ahead and update the transcript accordingly. But I can stop and start again the audio file 10 seconds in, or click far ahead, and the if statement is never triggered. The problem is very simple, but I'm baffled as to what is causing it. What am I missing here? Here is the code:
function updateTranscript(event, transcriptAsJson, divIdRoot, lastStepJson) {
var currentTime = event.jPlayer.status.currentTime;
var currentStepJson = lastStepJson;
currentStepJson.lastTime = currentTime;
/*
* If the user navigated the time forward or back
*/
if(currentTime >= (lastStepJson.lastTime + 0.75) || currentTime <= (lastStepJson.lastTime - 0.75)) {
//unhighlight lastStepJson.lastHighlightedId and
//any lastStepJson.additionalHighlightedIds
alert('user skip');
//...
//...
//...
lastStepJson
's schema looks like this, by the way.
{
'lastTime': 0.0,
'lastUpdate': 0.0,
'lastHighlightedId': 0
}