diff --git a/light9/ascoltami/index.html b/light9/ascoltami/index.html --- a/light9/ascoltami/index.html +++ b/light9/ascoltami/index.html @@ -45,7 +45,7 @@ var currentDuration = 0; var currentHighlightedSong = ""; var lastPlaying; - function updateCurrent() { + function updateCurrent(doneCallback) { $.getJSON("time", {}, function (data, status) { $("#currentSong").text(data.song); if (data.song != currentHighlightedSong) { @@ -63,6 +63,7 @@ $(data.playing ? "#cmd-play" : "#cmd-stop").addClass("active"); lastPlaying = data.playing; } + doneCallback(); }); } function showCurrentSong(uri) { @@ -131,11 +132,20 @@ }, }); + var raf = window.requestAnimationFrame || + window.mozRequestAnimationFrame || + window.webkitRequestAnimationFrame; + function updateLoop() { - updateCurrent(); - setTimeout(updateLoop, 200); + var whenDone = function () { + setTimeout(function () { + raf(updateLoop); + }, 50); + }; + updateCurrent(whenDone); } updateLoop(); + }); // ]]>