2010-10-13, 22:30
Actually what I do is a bit different, I use the time elapsed to calculate the time the song has started and use a timediff on that to display progress and time. I keep doing that until an announcement (or UDP broadcast) comes in:
So this way I only poll when something has actually changed, while the progress and time get update on the remote every second.
edit:
I need to refresh before posting or read better. It's what topfs2 said.
Code:
self = this;
[...]
else if (b[i].substring(0, 5) == "Time:") {
self.CurrentlyPlaying.Time = b[i].substring(5);
self.CurrentlyPlaying.Started = new Date() - (parseInt(self.CurrentlyPlaying.Time.substring(3, 5), 10) * 1000 + parseInt(self.CurrentlyPlaying.Time.substring(0, 2), 10) * 60000);
self.UpdateTime();
}
[...]
this.UpdateTime = function(){
if (self.CurrentlyPlaying.PlayStatus == "Playing") {
Now = new Date();
if (Now - self.LastPoll >= 980) {
self.Widgets.B8.label = time(Now - self.CurrentlyPlaying.Started);
self.LastPoll = Now;
Activity.scheduleAfter(980, self.UpdateTime);
}
}
else {
self.Widgets.B8.label = "";
}
};
edit:
I need to refresh before posting or read better. It's what topfs2 said.