Jump to content

[SOLVED] setInterval and setTimeout


markjoe

Recommended Posts

I am building an iTunes Web interface (yes, I know there are quite a few out there, but all I have found are either incomplete or I just didn't like them).

I did a setTimeout to wait the duration of the song to then update the current song info when the next song starts playing.(working fine so far)

I would also like to use setInterval to update the interface once a second to scroll the position indicator as you would expect in any media player.

example: setInterval('element.width=element.width+1',1000)

Is there a way to combine them do do both at the same time?

 

Maybe a conditional in the setInterval?

setInterval('if(position>=duration){element.width=element.width+1;position++}else{updateUI();}',1000)

I believe then updateUI() would have to clearInterval and re-call it with the new duration?

Link to comment
Share on other sites

That's what I think I am going to have to do. Like with the conditional in the setInterval.

I am just not quite sure how best to do it.

I worry a little about if the functions keep calling each other back and forth without ever returning, is that going to keep eating more memory as it runs?

 

I'll do some more testing with that idea and see what happens.

Link to comment
Share on other sites

Looks like

setInterval('if(position>=duration){element.width=element.width+1;position++}else{updateUI();}',1000)

will work. It's just a matter of fine tuning now.

I'll probably end up around 2-3 seconds. with the option to disable it completely.

I was mostly worried about slowly killing the browser the longer it played. Guess I'll just have to find out.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.