diff options
author | Florrie <towerofnix@gmail.com> | 2017-09-02 11:35:02 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2017-09-02 11:35:02 -0300 |
commit | 5d56a8f04fb08a1754d375a222aaf05d16950ca1 (patch) | |
tree | afaa7e727ac9d6a11ff7516c6db91f75bed1f23b /src/loop-play.js | |
parent | 9d507c390fad70937d8ba3e997fdeb069022eece (diff) |
Substitute pickers2 in place of pickers
Diffstat (limited to 'src/loop-play.js')
-rw-r--r-- | src/loop-play.js | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/loop-play.js b/src/loop-play.js index 212ee1c..c95c1c4 100644 --- a/src/loop-play.js +++ b/src/loop-play.js @@ -13,9 +13,8 @@ const FIFO = require('fifo-js') const EventEmitter = require('events') const promisifyProcess = require('./promisify-process') const killProcess = require('./kill-process') -const { getItemPathString } = require('./playlist-utils') - -const { safeUnlink } = require('./playlist-utils') +const { getItemPathString, safeUnlink } = require('./playlist-utils') +const { HistoryController, generalPicker } = require('./pickers2') const { getDownloaderFor, byName: downloadersByName, makeConverter @@ -294,12 +293,12 @@ class DownloadController extends EventEmitter { } class PlayController extends EventEmitter { - constructor(picker, player, playlist, downloadController) { + constructor(player, playlist, historyController, downloadController) { super() - this.picker = picker this.player = player this.playlist = playlist + this.historyController = historyController this.downloadController = downloadController this.currentTrack = null @@ -354,7 +353,7 @@ class PlayController extends EventEmitter { startNextDownload() { this.isDownloading = true - const picked = this.picker() + const picked = this.historyController.getNextTrack() this.nextTrack = picked if (!picked) { @@ -452,14 +451,13 @@ class PlayController extends EventEmitter { module.exports = async function startLoopPlay( playlist, { - picker, playerCommand = 'mpv', + pickerOptions, playerCommand = 'mpv', disablePlaybackStatus = false } ) { - // Looping play function. Takes one argument, the "picker" function, - // which returns a track to play. Stops when the result of the picker - // function is null (or similar). Optionally takes a second argument - // used as arguments to the `play` process (before the file name). + // Looping play function. Takes a playlist and an object containing general + // options (picker options, player command, and disable-playback-status). + // Stops when the history controller returns null. let player if (playerCommand === 'sox' || playerCommand === 'play') { @@ -487,8 +485,12 @@ module.exports = async function startLoopPlay( const downloadController = new DownloadController(playlist) await downloadController.init() + const historyController = new HistoryController( + playlist, generalPicker, pickerOptions + ) + const playController = new PlayController( - picker, player, playlist, downloadController + player, playlist, historyController, downloadController ) Object.assign(playController, {playerCommand}) |