markjoe Posted December 20, 2007 Share Posted December 20, 2007 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? Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 20, 2007 Share Posted December 20, 2007 why not just use one or the other two do both events? Quote Link to comment Share on other sites More sharing options...
markjoe Posted December 21, 2007 Author Share Posted December 21, 2007 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. Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 21, 2007 Share Posted December 21, 2007 once a second should not take up all that much memory; I just wouldn't go less then that - I probably would go a little bit higher than that; if it was me - but you make it do whatever it is that you want it to do. Quote Link to comment Share on other sites More sharing options...
markjoe Posted December 21, 2007 Author Share Posted December 21, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.