From c39d03335c713914a63527cb370fe026c4dc4660 Mon Sep 17 00:00:00 2001 From: jcass Date: Mon, 15 Feb 2016 09:10:39 +0200 Subject: [PATCH] Tweak timer display to show song duration as early as possible. Also initializes timers to '' instead of '0:00' - more consistent behaviour between streams and tracks. --- .../static/js/progress_timer.js | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/mopidy_musicbox_webclient/static/js/progress_timer.js b/mopidy_musicbox_webclient/static/js/progress_timer.js index 563737b..b715aa1 100644 --- a/mopidy_musicbox_webclient/static/js/progress_timer.js +++ b/mopidy_musicbox_webclient/static/js/progress_timer.js @@ -1,7 +1,7 @@ var progressTimer; var progressElement = document.getElementById('trackslider'); -var positionNode = document.createTextNode('0:00'); -var durationNode = document.createTextNode('0:00'); +var positionNode = document.createTextNode(''); +var durationNode = document.createTextNode(''); var START_BEATS = 5 // 0.5 seconds, needs to be less than 1s to prevent unwanted updates. var RUN_BEATS = 300 // 30 seconds assuming default timer update rate of 100ms @@ -48,20 +48,19 @@ function updateTimers(position, duration, isRunning) { positionNode.nodeValue = ''; durationNode.nodeValue = ''; $("#trackslider").val(0).slider('refresh'); - } else if (syncing) { - if (!targetPosition) { - // Waiting for Mopidy to provide a target position. - positionNode.nodeValue = '(wait)'; - } else { - // Busy seeking to new target position. - positionNode.nodeValue = '(sync)'; + } else { + durationNode.nodeValue = format(duration || Infinity); + if (syncing) { + if (!targetPosition) { + // Waiting for Mopidy to provide a target position. + positionNode.nodeValue = '(wait)'; + } else { + // Busy seeking to new target position. + positionNode.nodeValue = '(sync)'; + } + } else if (synced || streaming) { + positionNode.nodeValue = format(position);; } - } else if (streaming) { - positionNode.nodeValue = format(position);; - durationNode.nodeValue = '(n/a)'; - } else if (synced) { - positionNode.nodeValue = format(position); - durationNode.nodeValue = format(duration || 0); } if (ok) { @@ -111,7 +110,9 @@ function toInt(value) { function format(milliseconds) { if (milliseconds === Infinity) { - return '0:00'; + return '(n/a)'; + } else if (milliseconds == 0) { + return ''; } var seconds = Math.floor(milliseconds / 1000);