« 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.js17
1 files changed, 15 insertions, 2 deletions
diff --git a/backend.js b/backend.js
index ad13127..048aec5 100644
--- a/backend.js
+++ b/backend.js
@@ -368,7 +368,7 @@ class QueuePlayer extends EventEmitter {
   }
 
 
-  async play(item) {
+  async play(item, startTime) {
     if (this.player === null) {
       throw new Error('Attempted to play before a player was loaded')
     }
@@ -425,7 +425,7 @@ class QueuePlayer extends EventEmitter {
       } else {
         this.player.setPause(false)
       }
-      await this.player.playFile(downloadFile)
+      await this.player.playFile(downloadFile, startTime)
     }
 
     // playingThisTrack now means whether the track played through to the end
@@ -510,6 +510,15 @@ class QueuePlayer extends EventEmitter {
     return false
   }
 
+  async playOrSeek(item, time) {
+    if (item === this.playingTrack) {
+      this.seekTo(time)
+    } else {
+      this.queue(item, this.playingTrack)
+      this.play(item, time)
+    }
+  }
+
   clearPlayingTrack() {
     if (this.playingTrack !== null) {
       const oldTrack = this.playingTrack
@@ -531,6 +540,10 @@ class QueuePlayer extends EventEmitter {
     this.player.seekBack(seconds)
   }
 
+  seekTo(seconds) {
+    this.player.seekTo(seconds)
+  }
+
   togglePause() {
     this.player.togglePause()
   }