« get me outta code hell

timestamp files!!! - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/players.js
diff options
context:
space:
mode:
author(quasar) nebula <towerofnix@gmail.com>2021-07-13 23:14:20 -0300
committer(quasar) nebula <towerofnix@gmail.com>2021-07-13 23:14:20 -0300
commit382d5afc7e2ac24f67b7c891328b8b9bb7e91058 (patch)
tree87d97b4e20e48d936b33ef2ced898227af29a2e0 /players.js
parent80577b066352fe2dfecd706302e183a5705c193b (diff)
timestamp files!!!
Diffstat (limited to 'players.js')
-rw-r--r--players.js26
1 files changed, 16 insertions, 10 deletions
diff --git a/players.js b/players.js
index e22e505..b41ce0c 100644
--- a/players.js
+++ b/players.js
@@ -37,7 +37,7 @@ class Player extends EventEmitter {
     return this._process
   }
 
-  playFile(file) {}
+  playFile(file, startTime) {}
   seekAhead(secs) {}
   seekBack(secs) {}
   seekTo(timeInSecs) {}
@@ -87,7 +87,7 @@ class Player extends EventEmitter {
 }
 
 module.exports.MPVPlayer = class extends Player {
-  getMPVOptions(file) {
+  getMPVOptions(file, startTime) {
     const opts = ['--no-video', file]
     if (this.isLooping) {
       opts.unshift('--loop')
@@ -95,15 +95,18 @@ module.exports.MPVPlayer = class extends Player {
     if (this.isPaused) {
       opts.unshift('--pause')
     }
+    if (startTime) {
+      opts.unshift('--start=' + startTime)
+    }
     opts.unshift('--volume=' + this.volume * this.volumeMultiplier)
     return opts
   }
 
-  playFile(file) {
+  playFile(file, startTime) {
     // The more powerful MPV player. MPV is virtually impossible for a human
     // being to install; if you're having trouble with it, try the SoX player.
 
-    this.process = spawn('mpv', this.getMPVOptions(file).concat(this.processOptions))
+    this.process = spawn('mpv', this.getMPVOptions(file, startTime).concat(this.processOptions))
 
     let lastPercent = 0
 
@@ -146,11 +149,11 @@ module.exports.MPVPlayer = class extends Player {
 }
 
 module.exports.ControllableMPVPlayer = class extends module.exports.MPVPlayer {
-  getMPVOptions(file) {
-    return ['--input-ipc-server=' + this.socat.path, ...super.getMPVOptions(file)]
+  getMPVOptions(...args) {
+    return ['--input-ipc-server=' + this.socat.path, ...super.getMPVOptions(...args)]
   }
 
-  playFile(file) {
+  playFile(file, startTime) {
     this.removeSocket(this.socketPath)
 
     do {
@@ -160,7 +163,7 @@ module.exports.ControllableMPVPlayer = class extends module.exports.MPVPlayer {
 
     this.socat = new Socat(this.socketPath)
 
-    const mpv = super.playFile(file)
+    const mpv = super.playFile(file, startTime)
 
     mpv.then(() => this.removeSocket(this.socketPath))
 
@@ -252,13 +255,16 @@ module.exports.ControllableMPVPlayer = class extends module.exports.MPVPlayer {
 }
 
 module.exports.SoXPlayer = class extends Player {
-  playFile(file) {
+  playFile(file, startTime) {
     // SoX's play command is useful for systems that don't have MPV. SoX is
     // much easier to install (and probably more commonly installed, as well).
     // You don't get keyboard controls such as seeking or volume adjusting
     // with SoX, though.
 
-    this.process = spawn('play', [file].concat(this.processOptions))
+    this.process = spawn('play', [file].concat(
+      this.processOptions,
+      startTime ? ['trim', startTime] : []
+    ))
 
     this.process.stdout.on('data', data => {
       process.stdout.write(data.toString())