Howto: Use mpd and ncmpc++ like a pro
I tend to use the command line more often these days. When I have to do some task, I find it easier and faster to open a terminal and enter the necessary commands than using the GUI. The same thing goes for applications. When you know how to use a specific console program, it can be far more productive than a graphical application. Once you cross that “console barrier”, it’s hard to go back and you probably don’t want to. This is my attempt to sell mpd and ncmpcpp to you.
Mpd and ncmpc++ are perfect examples of these console programs. Mpd, also known as Music Player Daemon, is a powerful server side console application for playing music and ncmpc++ is one of the many console front-ends available for mpd (note that gui front-ends also exist). Mpd is cross-platform (although windows support is in a very experimental phase) and can also be controlled from an external device like a mobile phone. This makes it an ideal combination for a media server: your phone or other device as a remote control for your sound system running mpd. If you paid attention to what I said, you’ll conclude that mpd does not stream audio. I repeat: mpd does not stream audio. All playback occurs on the server. However, you output to a stream server like Icecast. Besides that, it also makes a great desktop music player program where both mpd and ncmpc++ are installed on the same computer. Inspired by K.Mandla‘s “how to become a pro at ..” I will show you how to do so and become a “pro” at using mpd and ncmpc++.
Setting Up mpd
First, you will need to install mpd. Every self respecting linux distribution has it in their software repositories, hence the installation of the package shouldn’t be a problem. For Ubuntu it would be “sudo apt-get install mpd”, for Arch Linux “sudo pacman -S mpd” and so on. For more information on installing mpd, you can always check out their extensive wiki: http://mpd.wikia.com/wiki/Install. The few configuration changes that have to be made, are done in /etc/mpd.conf for system-wide use, or in ~/.mpdconf for individual users. I will only explain setting it up for each individual user as it has several advantages over a system wide install such as setting up a separate music library, own playlists and resume of songs for each user individually.
1. Copy the system wide configuration file /etc/mpd.conf to ~/.mpdconf (~ denotes the users home directory):
cp /etc/mpd.conf ~/.mpdconf
2. Before we edit the config file, we will create some files and directories we will be using later on:
mkdir -p ~/.mpd/playlists touch ~/.mpd/mpd.db touch ~/.mpd/mpd.error touch ~/.mpd/log
3. Now edit ~/.mpdconf to reflect these settings:
music_directory "/full/path/to/your/music/directory" playlist_directory "~/.mpd/playlists" db_file "~/.mpd/mpd.db" log_file "~/.mpd/mpd.log" error_file "~/.mpd/mpd.error" pid_file "~/.mpd/mpd.pid" state_file "~/.mpd/mpdstate" bind_to_address "127.0.0.1" port "6600"
As you will see, there are two entries for each setting: one system wide and one user based. You have to comment out the system wide ones with # and enable the user based by uncommenting them and filling in the correct values (like mine above). The names of the settings speak for themselves and additional documentation is often added in the configuration file itself. Be sure to replace /full/path/to/your/music/directory with the correct path to your music directory and yourusername with your actual username. You can change the port if you want to, but there’s generally no point in doing that. You can also restrict access to mpd (remember, you can control it from a remote device) by uncommenting the password entry and supplying a password. Typically, you don’t have to mess with the audio output settings, but if you have problems later on remember these settings: Uncommenting the alsa output is then your best bet (since it ships with basically every linux distribution by default as it is included in the kernel).
There also exists a configuration page on their wiki.
Using mpd
Now that you have mpd installed and configured, you can start using it. There really isn’t much to say about using mpd. All you have to do is running the command mpd as user and creating the music library database file. It will look into your music_directory, create an entry for each music file and put information about it in mpd.db:
mpd --create-db
mpdThe cool thing about having a command line music player daemon is that you don’t need a X server running to play music. Are you tired of your music stopping when you log on and off your system? No problem, mpd will keep running when you log on and off. When you start mpd it will also resume the last song that was playing if you abruptly stopped the mpd daemon.
If mpd gives you any trouble like not starting up, no sound or not creating a mpd.db file, check out mpd.log and mpd.error. It will give you a headstart in figuring out what’s wrong.
Setting up ncmpc++
Now we still need something to control mpd with. Ncmpcpp is almost an exact clone of ncmpc but it contains some new features ncmpc doesn’t have. It’s been also rewritten from scratch in C++ and more importantly, it’s actively being developped. As I told before, there exist other clients both command line and graphical as web based. Hell, you can even get a client that runs on your Iphone or Ipod Touch. But I can assure you, ncmpc++ pretty much does it all: playlists, crossfading, tag editing, fetching lyrics… You name it, it’s got it.
As far as I know only Arch Linux, Gentoo and FreeBSD have ncmpcpp in their software repositories. So you might have to get your hands dirty with compiling it yourself. But hey, if you already get so far reading this, it really shouldn’t be a problem. People seriously considering a console music player, probably have the skill to compile it as well. Detailed installation instructions can be found on the ncmpcpp site.
I’m not really going into the configuration of ncmpc++. The default configuration will certainly do. Only when you intend to use the tag editor, you will have to set the proper path to the mpd music directory in ~/.ncmpcpp/config (the path you also filled in the config file of mpd). The rest is a bunch of color and format settings. You can also configure the shortcut keys in ~/.ncmpcpp/keys. More on the shortcut keys later.
Using ncmpc++
You can launch ncmpc++ in the terminal with:
ncmpcpp
When you launch it, you are welcomed by the playlist window that shows the songs of the playlist you are currently listening to
At the top, you see what menus are available and their corresponding key to access it (by default numbers from 1 to 7 and fn keys):
1:Help
2:Playlist
3:Browse
4:Search
5:Library
6:Playlist editor
7:Tag editor
The meaning of these menus are pretty obvious. A quick way to switch from the playlist to the browse menu and back is the tab key. The global keys to use in each menu are the arrow up and down to navigate and enter to select. To go to the parent directory you can use backspace. To start a selected song, press enter, s to stop a song and P to pause. > and < are used to go forward and backward one track. r is used to enable/disable repeat mode and z for random selection of the songs in the playlist. Deleting a song in your playlist can be done with d and clearing the whole playlist with c. You can increase and decrease the volume with + and -. If you want to quit ncmpc++, press q. As you can see, the shortcut keys somehow make sense, they mostly are the first character of the action you want to perform. Very easy to remember although it can be a bit overwhelming the first time.
When you stored a new music file in your music directory, you will have to update mpd’s database. I told you before that you can use this command:
mpd --create-dbbut ncmpc++ also has this functionality, accessible with u. So absolutely no need to quit ncmpcpp.
The previous short cuts were just the basic commands to get you started. This was only the beginning. You can for example cross-fade from one song to another with x. Fetching lyrics is l, looking up detailed information on the performing artist is I. The latter two perform a search on the internet. It’s possible it doesn’t find a match on the net, but that’s only the case with less known, most time local artist and songs. I tried it with some local artists from my country and it only missed one out of many. Another information key i gives you information about the music file itself such as file name and tags. You can go out of the lyrics, artist and file information screens by pressing the same button.
I’ll quickly look into searching your music database. If you have a playlist with a lot of songs or you have hundreds of artists, it’s very annoying to use the slow navigate arrow up and down key. You can instead do a quick forward and backward search with / and ?. If you want to perform a more complex search, you can always use the search menu (4 or F4) but I find that takes a lot of time and I don’t think a lot of people use it.
Integrated with ncmpc++ is an advanced tag editor. It’s one of the few command line players for mpd that have this. With this you can edit whatever tag you want of a music file in your database. The usage speaks for itself. As I told before, to get this functionality to work, you will have to supply the path the music directory in ~/.ncmpcpp/config.
All of the shortcut keys are configurable in ~/.ncmpcpp/keys. If you are unhappy with a certain key, you can change each one of them in that file.
This is as far as I’m willing to go with covering ncmpcpp’s functionality. I believe I’ve summed up the most important things. Feel free to notify me of other things I have overlooked. All the functionality and how to access them should be listed in the help menu (1 or F1).




[...] did though. I spend a little less than an hour this morning setting up mpd and ncmpc following the howto at nepherte.be. It worked for Crux as well as Arch, which came as no surprise. Technically the howto is for [...]
you should explain how to send a stream from mpd.
lets say I have all my music on mu server, and want to play it locally. is mpd an option for me then? if so, how?
You can certainly stream your music. There are 2 solutions, icecast and the built-in http streaming respectively. Both involve changing the audio output in the .mpdconf configuration file.
The easiest solution is defintely the built-in http streaming, which requires at least version 0.15 of mpd. An example for the config changes is: