simple, modular music player written in node.js
disclaimer: for personal use only - make sure you configure nodeplayer appropriately so that others can't access your music. I take no responsibility eg. if your streaming services find you are violating their ToS, you're running this software entirely on your own risk!
This repository contains the core nodeplayer application. As a standalone component it is rather useless, as it is meant to be extended by other modules. In essence, the core application manages a playback queue and initializes any modules that you have configured it to load. Modules are given various ways to manipulate the queue, but without modules you can't really do anything!
Apart from the core, nodeplayer is split up into several components where each component belongs to one of two categories:
- Backend modules: Sources of music
- Plugin modules: Extend the functionality of the core in various ways
By keeping nodeplayer modular it is possible to use it in a wide variety of scenarios, ranging from being a basic personal music player to a party playlist manager where partygoers can vote on songs. Or perhaps configure it as a streaming music player to your mobile devices and when you come home, you can simply switch music sources over to your PC since the music plays back in sync. More cool functionality can easily be implemented by writing new modules.
TODO
The core provides several functions for managing the queue to plugins, and through the use of hooks the core will call the plugin's hook functions (if defined) at certain times.
A plugin must export at least an init function:
exports.init = function(player, callback) {...};
- Called for each configured plugin when nodeplayer is started.
- Arguments:
- player: reference to the player object in nodeplayer core, store this if you need it later
- callback: callback must be called with no arguments when you are done initializing the plugin. If there was an error initializing, call it with a string stating the reason of the error.
And there you have it, the simplest possible plugin. Now let's take a look at hook functions!
Plugin hook functions are called by the core (usually) before or after completing
some task. For instance onSongEnd
will be called with the song that ended as
the argument whenever a song ends. Hooks are called by calling:
player.callHooks('hookName', [arg1, arg2, ...]);
This will call the hook function hookName
in every plugin that has defined a
function with that name, in the order the plugins were loaded, with arg1, arg2, ...
as arguments. Simply define the hook function in the plugin as such:
exports.hookName = function(arg1, arg2, ...) {...};
If any hook returns a truthy value it is an error that will also be returned by
callHooks()
, and potential further hooks will not be ran.
onSongChange(np)
- song has changed tonp
onSongEnd(np)
- songnp
endedonSongPause(np)
- songnp
was pausedonSongPrepareError(song, err)
- preparingsong
failed witherr
onSongPrepared(song)
- preparingsong
succeededonPrepareProgress(song, s, done)
- data (s
bytes) related tosong
written to disk. Ifdone
true then we're done preparing the song.onEndOfQueue()
- queue endedonQueueModify(queue)
- queue was potentially modifiedpreAddSearchResult(song)
- about to add search resultsong
, returning a truthy value rejects search resultpreSongsRemoved(pos, cnt)
- about to removecnt
amount of songs starting atpos
. TODO: these should probably be possible to rejectpostSongsRemoved(pos, cnt)
- removedcnt
amount of songs starting atpos
preSongsQueued(songs, pos)
- about to queuesongs
topos
postSongsQueued(songs, pos)
- queuedsongs
topos
preSongQueued(song)
- about to queuesong
topos
postSongQueued(song)
- queuedsong
topos
sortQueue()
- queue sort hookonPluginInitialized(plugin)
-plugin
was initializedonPluginInitError(plugin, err)
-err
while initializingplugin
onPluginsInitialized()
- all plugins were initializedonBackendInitialized(backend)
-backend
was initializedonBackendInitError(backend, err)
-err
while initializingbackend
onBackendsInitialized()
- all backends were initialized
TODO
- nodeplayer The core music player
- nodeplayer-client CLI client for controlling nodeplayer
- nodeplayer-player CLI audo playback client
- nodeplayer-defaults Default configuration file