From 872dacbdbfa44f14b26f1edd1d36b06e0cfd14fe Mon Sep 17 00:00:00 2001 From: Florrie Date: Tue, 4 Jun 2019 10:53:36 -0300 Subject: Don't flicker queue duration to a lesser value ...while a new track is "playing" but its time data isn't yet available (because the player process hasn't actually reported any data yet, probably because the player/file itself is still loading). --- ui.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/ui.js b/ui.js index d9db800..eb6b8f9 100644 --- a/ui.js +++ b/ui.js @@ -1117,7 +1117,23 @@ class AppElement extends FocusElement { trackRemainSec = lenSecTotal - curSecTotal } - const index = items.indexOf(this.playingTrack) + 1 + // Index of tracks "ahead" of the current track. All tracks before this + // index are accounted for by either being behind the current track (and + // thus ignorable) or being the current track (and thus having its + // remaining duration be counted by the time data stored on the playback + // info element). + let index = 0 + + if (this.playingTrack) { + index = items.indexOf(this.playingTrack) + // If it's NOT counted by the playback info element's time data yet, + // we skip this - the current track is counted as "ahead" and its + // duration will be tallied like the rest of the "ahead" tracks. + if (Object.keys(this.playbackInfoElement.timeData).length) { + index++ + } + } + const aheadRemainSec = items.slice(index).reduce(durationFn, 0) const totalRemainSec = trackRemainSec + aheadRemainSec @@ -2178,6 +2194,7 @@ class PlaybackInfoElement extends DisplayElement { this.trackNameLabel.text = track.name this.progressBarLabel.text = '' this.progressTextLabel.text = '(Starting..)' + this.timeData = {} this.fixLayout() } @@ -2187,6 +2204,7 @@ class PlaybackInfoElement extends DisplayElement { this.progressTextLabel.text = '' this.trackNameLabel.text = '' this.downloadLabel.text = '' + this.timeData = {} this.fixLayout() } } -- cgit 1.3.0-6-gf8a5