From 382d5afc7e2ac24f67b7c891328b8b9bb7e91058 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 13 Jul 2021 23:14:20 -0300 Subject: timestamp files!!! --- players.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'players.js') 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()) -- cgit 1.3.0-6-gf8a5