« get me outta code hell

Don't flicker queue duration to a lesser value - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2019-06-04 10:53:36 -0300
committerFlorrie <towerofnix@gmail.com>2019-06-04 10:53:36 -0300
commit872dacbdbfa44f14b26f1edd1d36b06e0cfd14fe (patch)
treee87b8856d13d6b31746c850588938273e85e031c
parent9802be29ba650ee338d9601d3614e70ccdc52a45 (diff)
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).
-rw-r--r--ui.js20
1 files changed, 19 insertions, 1 deletions
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()
   }
 }