dcsimg

Music on the Command-Line

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:

music_directory "/home/scott/music"
playlist_directory "/home/scott/.mpd/playlists"
db_file "/home/scott/.mpd/mpd.db"
log_file "/home/scott/.mpd/mpd.log"
error_file "/home/scott/.mpd/mpd.error"
pid_file "/home/scott/.mpd/mpd.pid"
state_file "/home/scott/.mpd/mpdstate"
user "scott"
bind_to_address "any"
port "6600"

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.

Comments on "Music on the Command-Line"

dalfa

MPD is also in Mandriva’s repositories.

registerhater

Why not just SSH into another machine and run mplayer?

I hate how software written by amateurs doesn’t abide by good engineering principles — namely KISS.

If you don’t know/haven’t heard of KISS, and you code, please stop right now and give up.

bamjive06

Anything for Solaris guys?

tink

A letter of condolence?

digital_slack

even better — use ncmpcpp — a fork of ncmpc with more features and such

bugmenot

Even better, use moc instead of mpd. Works more like a typical music player, just on the command-line. No need to set up music repositories and use relative paths from there.

mhazen

Why? Because running an X app across the network is godforsakenly less efficient than sending back a stream of audio. Because you can’t connect from multiple locations to one playing stream. Because running mplayer across a network requires the user to have a shell acount on the machine. Because it would require X on the user’s machine, which most Windows users won’t have. And yes, this project has Windows clients availabl.

It’s called “this software is more complex and uses better software engineering practices than you apparently understand”. If you haven’t heard about it before, and you code, you should be ashamed of yourself for showing your ass in public like this.

Whoo, *more* features. Must be better then.

In reality, the so-called extra features are just an excuse to justify re-writing in C++ (blergh!).

Oh my goodness! an incredible article dude. Thank you Nevertheless I’m experiencing situation with ur rss . Don’t know why Unable to subscribe to it. Is there anybody getting equivalent rss problem? Anybody who knows kindly respond. Thnkx

Wow that was strange. I just wrote an really long comment but after I clicked submit my comment didn’t show up. Grrrr… well I’m not writing all that over again. Anyway, just wanted to say excellent blog!

You are my aspiration, I have few web logs and rarely run out from to brand.

hello!,I love your writing so a lot! proportion we keep in touch extra approximately your post on AOL? I need a specialist on this space to solve my problem. May be that’s you! Looking ahead to look you.

Sites of interest we’ve a link to.

I was wondering if you ever thought of changing the page layout of your website? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having 1 or 2 images. Maybe you could space it out better?

Hello baby
That article is very helpful for me,i like it,thank you!
Wholesale Oakley sunglasses matte navy orion blue iridium outlet http://www.fleetsale.ru/new-arrival-oakleys-767.html

Usually posts some incredibly exciting stuff like this. If you?re new to this site.

Although web sites we backlink to beneath are considerably not related to ours, we really feel they may be essentially worth a go as a result of, so possess a look.

o05kau nxpridevtfob, [url=http://pmcbthfgzptc.com/]pmcbthfgzptc[/url], [link=http://iswnlkuamvva.com/]iswnlkuamvva[/link], http://stypzvqyowts.com/

Here are a few of the web-sites we suggest for our visitors.

The information mentioned in the write-up are a few of the most beneficial out there.

Leave a Reply