Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

Using onTime() to run a function every 5 seconds?


Hey guys!

As the title says, I'm trying to run a function every 5 seconds using onTime(). I found this thread from a while ago:

http://www.longtailvideo.com/support/forums/jw-player/javascript-interaction/18350/how-to-the-change-the-frequency-of-the-ontime-event/

in which someone suggests using a counter to trigger an event only once. From that, I diddled together something like this:

bc.. JWP.onTime(function(event){
var time= Math.floor(event.position),
counter = 0;

if (time == counter){
counter+=5;
//blah blah code
}
});


Sorry if there are any syntax errors, I'm pretty new to this! Anyway, the problem is is that the code triggers more than once. I've been wracking my brains on this for quite a while now! Did I make a noob mistake? Is there a better way to do this? Cheers in advance for any help!

2 Community Answers

JW Player

User  
3 rated :

Solved! Turns out it was a pretty noob mistake! Here is my code to make things run every [x] seconds for anyone who needs it!

bc.. var counter = 0,
time;
JWP.onTime(function(event){
var time= Math.floor(event.position),

if (time == counter){
counter+=[insert seconds here];
//blah blah code
}
});

Ethan Feldman

JW Player Support Agent  
0 rated :

Glad you got it!

This question has received the maximum number of answers.