From 0890f592ecdada66e8e264d6201e43ed0c6bf7ac Mon Sep 17 00:00:00 2001 From: Florrie Date: Mon, 6 Apr 2020 22:03:17 -0300 Subject: Auto-DJ --- players.js | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'players.js') diff --git a/players.js b/players.js index 868129d..5fe4714 100644 --- a/players.js +++ b/players.js @@ -19,6 +19,7 @@ class Player extends EventEmitter { this.isLooping = false this.isPaused = false this.volume = 100 + this.volumeMultiplier = 1.0 } set process(newProcess) { @@ -41,6 +42,8 @@ class Player extends EventEmitter { seekBack(secs) {} volUp(amount) {} volDown(amount) {} + setVolume(value) {} + updateVolume() {} togglePause() {} toggleLoop() {} setPause() {} @@ -61,6 +64,25 @@ class Player extends EventEmitter { this.emit('printStatusLine', data) } } + + setVolumeMultiplier(value) { + this.volumeMultiplier = value + this.updateVolume() + } + + fadeIn() { + const interval = 50 + const duration = 1000 + const delta = 1.0 - this.volumeMultiplier + const id = setInterval(() => { + this.volumeMultiplier += delta * interval / duration + if (this.volumeMultiplier >= 1.0) { + this.volumeMultiplier = 1.0 + clearInterval(id) + } + this.updateVolume() + }, interval) + } } module.exports.MPVPlayer = class extends Player { @@ -72,7 +94,7 @@ module.exports.MPVPlayer = class extends Player { if (this.isPaused) { opts.unshift('--pause') } - opts.unshift('--volume=' + this.volume) + opts.unshift('--volume=' + this.volume * this.volumeMultiplier) return opts } @@ -112,6 +134,8 @@ module.exports.MPVPlayer = class extends Player { this.printStatusLine(getTimeStrings({curHour, curMin, curSec, lenHour, lenMin, lenSec})) } + + this.updateVolume(); }) return new Promise(resolve => { @@ -177,7 +201,11 @@ module.exports.ControllableMPVPlayer = class extends module.exports.MPVPlayer { this.volume = value this.volume = Math.max(0, this.volume) this.volume = Math.min(100, this.volume) - this.sendCommand('set_property', 'volume', this.volume) + this.updateVolume() + } + + updateVolume() { + this.sendCommand('set_property', 'volume', this.volume * this.volumeMultiplier) } togglePause() { -- cgit 1.3.0-6-gf8a5