Remotely control your tunes with MPD and ncmpc.
Linux has several good music players (RealPlayer, Totem, Banshee), some great music players (XMMS, Rhythmbox), and one awesomely fantastic music player that beats those found on any other operating system: Amarok. Those are all very cool programs, with one thing in common: a GUI.
So what if you donâ€™t want or need a GUI? What if you want to control the music your computer is playing from across the room? What if you want the ultimate in speed and stability? Then you want a music player that was built for the command-line. You want the one-two, knock-out combination of MPD (Music Player Daemon) and ncmpc.
Start by installing MPD. You can get the source code from http://www.musicpd.org/files.shtml, or via your distroâ€™s repository. Debian and K/Ubuntu users, for instance, can simply use apt-get install mpd.
Once MPD is installed, you need to create a configuration file. If you control your machine, youâ€™ll want it to end up at /etc/mpd.conf; if you canâ€™t create that file, or youâ€™d rather have it in your home directory, create ~/.mpdconf. The easiest way to create the file is to copy mpdfconf.example to the new location and then edit the new copy. The example configuration file is very well commented, so you should be able to figure things out. Nonetheless, hereâ€™s a useful /etc/mpd.conf file:
MPD first scans your music collection and then creates a database listing every file that it found, hence the db_file parameter. The log_file and error_file options are obvious, while the pid_file makes it easier to kill the program if it wigs out. The state_file saves your current playlist, song, and location within that song so that all that can restored when you restart MPD.
To create and store playlists, specify the playlist_directory; be sure to manually create that directory, or MPD wonÃt start like it should the very first time. Specify the user so that if MPD is started by root, it wonÃt run as root, and will instead run as the user you choose. The bind_to_address and port are the defaults, and are used by the programs that connect to MPD and actually play the music indexed by MPD.
Finally, the first parameter, music_directory, points to the location of your music collection. In the case of /home/scott/music, this is actually a symbolic link pointing to an external drive. If you have multiple drives for you collection, simply include a soft link on music pointing to the other drive. MPD happily follows that link to index the songs found on that drive as well.
The first time you run MPD â€” by typing mpd, naturally â€” you need to wait while the program indexes all of your music. If you have a large music collection, this could take an hour or more. Once itÃs done, you need to make sure that MPD re-indexes your tunes on a regular basis to discover additions. The command to update the MPD database is mpc update, and if you just added or deleted some music, go ahead and type that in, and then wait. If you want something a bit more regular, add /usr/bin/mpc update as a cron job to your computerÃs nightly task list.
You actually have quite a few choices when it comes to a client to connect to MPD and play music. A nice list can be found at http://www.musicpd.org/clients.shtml. The best CLI client is ncmpc, which can be installed using your package manager or can be downloaded as source from http://www.musicpd.org/ncmpc.shtml.
Start ncmpc with ncmpc and the program should open. If you changed the host and port in your MPD conf file, though, type man ncmpc and read the instructions for connecting. Press the number 1 if you need Help.
Press 3 to browse your musicÃs directory structure. When you find a song you want to hear, use your arrow keys to go to it and press Enter. You should immediately hear it start playing. To add a song to the playlist, press Space instead of Enter. To play the tunes youÃve selected, press 2 to view your playlist and then press Enter. To pause, press Shift-P.
MPD and ncmpc arenÃt for everyone, but the combination beautifully meets the needs of many people. In fact, even if you love Amarok, you may find yourself using ncmpc instead, simply because itÃs faster and simpler, and because you can change the music thatÃs playing without vacating the couch.
teaches at Washington University in St. Louis, consults for WebSanity, and writes for SecurityFocus and Linux Magazine
. His latest book, Linux Phrasebook
is in stores now. You can reach him at email@example.com