diff --git a/lib/javascript.js b/lib/javascript.js index 028d382..4472ffa 100644 --- a/lib/javascript.js +++ b/lib/javascript.js @@ -2,12 +2,40 @@ song_length = {$song_length}; song_position = {$song_position}; + song_min = {$initialmin}; + song_sec = {$initialsec}; + mpd_state = '{$mpd_state}'; {literal} + update_int = null; + + function format_time(number) { + if (number < 10) { + return '0' + number.toString(); + } + else { + return number.toString(); + } + } + function update_progress() { + //set the interval if it hasn't been set already. + if (update_int == null) { + update_int = setInterval('update_progress()', 1000); + } + + if (song_position < song_length) { + song_position = song_position + 1; + song_sec = song_sec + 1; + if (song_sec >= 60) { + song_sec = 0; + song_min = song_min + 1 + } + } + progressbar = document.getElementById('progressbar'); new_margin = Math.round(200 - ((song_position / song_length) * 200)); @@ -15,17 +43,16 @@ new_margin_string = new_margin + 'px'; progressbar.style.marginRight = new_margin_string; + document.getElementById('min').innerHTML = format_time(song_min); + document.getElementById('sec').innerHTML = format_time(song_sec); //alert(progressbar.style.marginRight + ' - ' + new_margin_string); - if (song_position < song_length) { - song_position = song_position + 1; - } - } if (mpd_state == 'play') { - update_int = setInterval('update_progress()', 1000); + //start off with a shorter interval. this should make the whole thing a little more accurate. + setTimeout('update_progress()', 750); } {/literal} diff --git a/lib/page.php b/lib/page.php index a2e365c..34ae41d 100644 --- a/lib/page.php +++ b/lib/page.php @@ -38,11 +38,15 @@ $smarty->assign('coversize', $_CONFIG['album_cover_size']); } - $time_left = (($mympd->current_track_length - $mympd->current_track_position) + 2) * 1000; + $time_left = (($mympd->current_track_length - $mympd->current_track_position) + 1) * 1000; $initialprogress = round(200 - (($mympd->current_track_position / $mympd->current_track_length) * 200)); $smarty->assign('initialprogress', $initialprogress); + $smarty->assign('initialmin', date('i', $mympd->current_track_position)); + $smarty->assign('initialsec', date('s', $mympd->current_track_position)); + $smarty->assign('totalmin', date('i', $mympd->current_track_length)); + $smarty->assign('totalsec', date('s', $mympd->current_track_length)); //echo $time_left / 1000; diff --git a/templates/default/control.html b/templates/default/control.html index 82bde6c..6139ec0 100644 --- a/templates/default/control.html +++ b/templates/default/control.html @@ -1,7 +1,9 @@ -
- + +