« get me outta code hell

new GhostPlayer class & support 👻 - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/backend.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-05-14 19:53:31 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-05-14 19:53:31 -0300
commit7f2461a60fba35013551fdb27ba0bb8d0720021d (patch)
treebcaaf43e2d54ffeff7a400c3a1b32480e118c8eb /backend.js
parent56ad0bab6cbcc079887d5a5086cb116844bc351e (diff)
new GhostPlayer class & support 👻
This also makes the UI not explode when duration strings aren't
available for progress bar display, and shows getTimeStringsFromSec
how to handle that.
Diffstat (limited to 'backend.js')
-rw-r--r--backend.js13
1 files changed, 13 insertions, 0 deletions
diff --git a/backend.js b/backend.js
index 6576868..232d912 100644
--- a/backend.js
+++ b/backend.js
@@ -660,6 +660,12 @@ class QueuePlayer extends EventEmitter {
     this.emit('set loop queue at end', !!value)
   }
 
+  setDuration(duration) {
+    if (this.player.setDuration) {
+      setTimeout(() => this.player.setDuration(duration))
+    }
+  }
+
   get remainingTracks() {
     const index = this.queueGrouplike.items.indexOf(this.playingTrack)
     const length = this.queueGrouplike.items.length
@@ -776,6 +782,13 @@ export default class Backend extends EventEmitter {
       })
     }
 
+    queuePlayer.on('playing', track => {
+      if (track) {
+        const metadata = this.getMetadataFor(track)
+        queuePlayer.setDuration(metadata.duration)
+      }
+    })
+
     return queuePlayer
   }