« get me outta code hell

Don't add saved time data duration if not playing - 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:45:12 -0300
committerFlorrie <towerofnix@gmail.com>2019-06-04 10:45:12 -0300
commit9802be29ba650ee338d9601d3614e70ccdc52a45 (patch)
treef45ce78f20120c038e78665743f8413388b4b185
parentf7282caeff3971d375f72e797445f6e315e024b4 (diff)
Don't add saved time data duration if not playing
I.e. if we aren't playing a track, don't take into account the remaining
time of the "current track" saved by the playback info element if we
aren't actually playing any track right now.
-rw-r--r--ui.js8
1 files changed, 6 insertions, 2 deletions
diff --git a/ui.js b/ui.js
index 6127f0f..d9db800 100644
--- a/ui.js
+++ b/ui.js
@@ -1110,8 +1110,12 @@ class AppElement extends FocusElement {
       return acc + (metadata && metadata.duration) || 0
     }
 
-    const { curSecTotal = 0, lenSecTotal = 0 } = this.playbackInfoElement.timeData
-    const trackRemainSec = lenSecTotal - curSecTotal
+    let trackRemainSec = 0
+
+    if (this.playingTrack) {
+      const { curSecTotal = 0, lenSecTotal = 0 } = this.playbackInfoElement.timeData
+      trackRemainSec = lenSecTotal - curSecTotal
+    }
 
     const index = items.indexOf(this.playingTrack) + 1
     const aheadRemainSec = items.slice(index).reduce(durationFn, 0)