« get me outta code hell

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:
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
   }