my package of the day: mpd – the Music Player Daemon

There are dozens of nice music players around, that’s for sure. You can choose between featur rich killer applications like Rhythmbox or Amarok, use old-school but up to date standards like XMMS or even a console classic like mp3blaster. Most of the standard players have in common, that the interface and the player itself are the same. That’s normal and therefore everything is fine. But maybe you are in a situation where you prefer playing music on a remote machine, only have a console or just don’t want your music player to stay open while playing. Huh?

Okay, again: Imagine, you set a machine dedicated for playing music. You put it into a corner, it has no keyboard, just a network interface. How do you proceed? Ah, you install mp3blaster via ssh and let mp3blaster run in the console, right? That’s fine and mp3blaster really kicks ass. But… With mp3blaster you are forced to have a shell account on the machine, just for playing music. Mp3blaster has a lot of features, but it has only one interface and you have to stick to it – and at least you also have to get into the „screen“ business for letting the player run while not being logged in.

So what’s the alternative? Well: Imagine a music player daemon, that keeps your music collection and listens for clients telling him, what to play next. You don’t even need to imagine the music player daemon, just have a look at the „Music Player Daemon“ – abbreviated „mpd“. It’s idea is to completely split user interface and player daemon, enabling you to choose between different user interfaces (from console to gui) and to manage a remote daemon without the need of logging into the machine directly.

Now let’s test it, right away. First, we install „mpd“ by calling „aptitude install mpd“. This will enroll the daemon and start it right away. „mpd“ organises its files in „/var/lib/mpd“ and expects music by default in „/var/lib/mpd/music“. Strange location, isn’t it? While you are free to configure the mpd daemon in /etc/mpd.conf, the easiest way of getting you music into the daemon is to symlink your directory/directories. I keep my music collection in /home/ccm/Music. Therefore I run „sudo ln -s /home/ccm/Music /var/lib/mpd/music/ccm“. Now you have to take a short break and think about access rights: While mpd runs as user „mpd“, which is a good idea, you need to make sure, that your music files are accessible to mpd. I ran into trouble as my mp3 files provided read access only the owner (me). Therefore I needed to decided whether to run mpd as „ccm“, chown my music to „mpd“ or to extend access rights. I decided for last version and just chmod’ed the music files and directories (see below). Now you need to tell mpd that there is new music around. Just run „sudo mpd –create-db“ and it should crawl your library quite fast. So until here we took the following steps:

# install mpd
$ sudo aptitude install mpd
# symlink current music to mpd music library
$ sudo sudo ln -s /home/ccm/Music /var/lib/mpd/music/ccm
# make sure, mpd can access the music
# please be careful with this
$ find /home/ccm/Music -type d -exec chmod 755 '{}' \;
$ find /home/ccm/Music -type f -exec chmod 644 '{}' \;
# tell mpd about the music
$ sudo mpd --create-db

A first graphical approach: Ario

Now let’s listen to some music! But stop: We need a client! Until now we only installed the daemon. An „apt-cache search mpd client“ gives you a brief overview over possible clients. I’d suggest you install „mpc“ (the classic command line tool), „ncmpc“ (an enhanced menu driven client), ario (a gtk client) for now, to see differences. Therefore run „sudo aptitude install mpc ncmpc ario“. Give ario a try if you prefer a gui. Like all clients, ario tries to connect to a mpd instance on the localhost by default. You should already see your music like this:

bildschirmfoto-ario.png

The mpd daemon expects a playlist from you. This is party on the lower side of the interface. Feel free to drag and drop the name of a band/musician, an album or even just a single track into this area and hit play. Hey, mpd play music! But that’s actually like the situation before…

A first console approach: ncmpc

For getting the difference, close the player by clicking on the X on the upper right side. Ario will totally disappear (feel free to check with „ps aux | grep ario“, but the music will continue to play. Nice. Now let’s get it even more abstract and open a console and start „ncmpc“. In this player you can switch to the different „tabs“ by hitting a key from 1 to 5. „2“ is the current playlist, „3“ a file browser. You can hit ENTER on a file in the playlist, and it will play, while DELETE will remove it from the playlist. In the browser, you hit SPACE on a directory and it will be added to the file list or ENTER on a single track. This way you can build a huge playlist very fast.

Let your command line completion work: mpc

With Ario and ncmpc you can already choose between a gui and console interface for controlling your music player. As I really like working on the console, I was happy to see, that the TAB completion from Bash and ZSH support the „mpc“ command, which is the standard console interface. With „mpc“ you will normale use one of the following commands:

# add a directory to the playlist
$ mpc add directory
# add a single track to the playlist
$ mpc add file
# play a track by number from the playlist
$ mpc play NUMBER
# show current playlist
$ mpc playlist
# update the current database as new files have been added
$ mpc update
# list all availabe music
$ mpc listall

If you are a ZSH user like I am, you will be pleased by the heavy TAB completion support. All commands and file names can be completed which actually makes you faster than bothering with any gui. The Bash support is okay, but not that sophisticated. If you don’t know, what I am talking about: never mind. You will, one day :)

Let the browser work: Relaxx

A crazy Ajax guru here from Berlin wrote „Relaxx“, a nice web interface to mpd. Check out the project page for screenshots and the sourceforge page for downloads:

relaxx-light.png

I think this is enough for a first insight into „mpd“ and its clients. If you like the idea, you should read about connecting to remote mpd instances, so you are able to use your local client for a daemon running on a different machine, enabling authentication in mpd or maybe think about running mpd just on your local machine as it is a nice way of keeping your music collecting while being able to choose a client depending on the situation you are in. The mpd wiki is a great place to start gathering further information. You’ll find that a lot of utilities are available – from pidgin plugin for showing the music you are listening to a gnome panel applet. Always have in mind, how strong you are while being on the console as you can even use pipes when using mpc… Have fun.