diff options
Diffstat (limited to 'ui.js')
-rw-r--r-- | ui.js | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/ui.js b/ui.js index f9f066e..f432ebe 100644 --- a/ui.js +++ b/ui.js @@ -7,8 +7,10 @@ const processSmartPlaylist = require('./smart-playlist') const UndoManager = require('./undo-manager') const { - shuffleArray, - getTimeStringsFromSec + commandExists, + getTimeStringsFromSec, + promisifyProcess, + shuffleArray } = require('./general-util') const { @@ -54,6 +56,7 @@ const { const TuiTextEditor = require('tui-text-editor') const { promisify } = require('util') +const { spawn } = require('child_process') const fs = require('fs') const open = require('open') const path = require('path') @@ -181,6 +184,7 @@ class AppElement extends FocusElement { this.backend = backend this.telnetServer = null this.isPartyHost = false + this.enableAutoDJ = false this.config = Object.assign({ canControlPlayback: true, @@ -330,6 +334,7 @@ class AppElement extends FocusElement { playingTrack && {element: this.playingControl}, {element: this.loopingControl}, {element: this.pauseNextControl}, + {element: this.autoDJControl}, {element: this.volumeSlider}, {divider: true}, previous && {label: `Previous (${previous.name})`, action: () => this.SQP.playPrevious(playingTrack)}, @@ -387,6 +392,12 @@ class AppElement extends FocusElement { getEnabled: () => this.config.canControlPlayback }) + this.autoDJControl = new ToggleControl('Enable Auto-DJ?', { + setValue: val => (this.enableAutoDJ = val), + getValue: val => this.enableAutoDJ, + getEnabled: () => this.config.canControlPlayback + }) + this.bindListeners() this.initialAttachListeners() @@ -491,7 +502,7 @@ class AppElement extends FocusElement { this.removeQueuePlayerListenersAndUI(queuePlayer) } - handlePlaying(track, oldTrack, queuePlayer) { + async handlePlaying(track, oldTrack, queuePlayer) { const PIE = this.getPlaybackInfoElementForQueuePlayer(queuePlayer) if (PIE) { PIE.updateTrack() @@ -503,6 +514,17 @@ class AppElement extends FocusElement { this.queueListingElement.selectAndShow(track) } } + + if (track && this.enableAutoDJ) { + queuePlayer.setVolumeMultiplier(0.5); + const message = 'now playing: ' + getNameWithoutTrackNumber(track); + if (await commandExists('espeak')) { + await promisifyProcess(spawn('espeak', [message])); + } else if (await commandExists('say')) { + await promisifyProcess(spawn('espeak', [message])); + } + queuePlayer.fadeIn(); + } } handleReceivedTimeData(data, queuePlayer) { |