An introduction to the XMMS2 package

Posted by Steve on Mon 19 Mar 2007 at 06:11

Over the past few years I've used the venerable XMMS application for playing back all my audio content. After reading recently that this project has been mothballed, seeing no future updates, I decided to try the successor project XMMS2. Here's how I got on.

My XMMS experience dates back many years, to the time when I started using MP3s, and later OGG Vorbis files, as my primary means of listening to music.

Armed with a couple of plugins for the playback of different audio types, and a simple plugin to give on-screen notifications I've been very happy with xmms, apart from the occasional problem with playing music stored on an NFS share it sits there in the corner of my desktop and just does its job.

My use of xmms

My use of xmms was pretty standard. I added a couple of skins, a couple of plugins, and I bound my keyboard's multimedia keys to make them function as expected.

The only unusual thing I'd done was install the xmms-osd-plugin package - this shows a little message over the top of my desktop whenever the track being played changes, or if I hit stop/pause/play/next/prev. This plugin is very simple, but incredibly handy when I have the main GUI minimized.

Installing xmms2

The basic installation of the software can be conducted with the following command:

apt-get install xmms2

However this doesn't explain things completely. In the past the XMMS package contained a single binary which presented a GUI and played the music.

With XMMS2 things have changed. Instead of a single application being responsible both for the playback and the user interface the system is split into a client and a server.

The xmms2 package contains nothing itself. Instead it specifies some packages which should be installed:

xmms2-core

The xmms2-core package contains a small daemon which will accept commands to add files to the playlist, to play/pause and advance backwards and forwards through the playlist.

xmms2-client-cli

This package contains a simple command line interface to instruct the daemon to actually carry out jobs.

What does this mean? Well it means that you don't get a GUI by default. Instead you get a small server daemon which will listen for command and carry them out, and a simple program to send those commands.

To get started you'd run:

/usr/bin/xmms2d &

This will start the server daemon in the background.

Now you can add music to the playlist and start playback with the xmms2 client program:

/usr/bin/xmms2 radd /home/mp3
/usr/bin/xmms2 play

Here we've used the radd command to recursively add the contents of a directory to the current playlist. Then the play command to actually start playback.

Once we're done we could run "xmms2 quit" to cause the server to exit.

Or instead you could install a graphical client, to provide an interface which doesn't require any command line access. I'm currently very happy with the gxmms2 package, except for one omission we'll correct shortly.

Configuring

The configuration of the new package is something else that has changed. You may find the configuration files beneath the directory ~/.config/xmms2

Upon a fresh installation you'll see something like this:

/home/skx/.config/xmms2
|-- bindata
|-- clients
|   |-- cli.conf
|   |-- gxmms2.conf
|-- medialib.db
|-- shutdown.d
|-- startup.d
`-- xmms2.conf

Here you can see a sub-directory for each of the clients, the command line one which is installed by default and the graphical gxmms2 package I installed afterward.

In addition you can see that there are two directories startup.d and shutdown.d. These directories are very useful as they allow you to run programs when the music-playing daemon starts or stops.

If you install additional plugins you might need to install symbolic links in there manually. For example the xmms2-scrobbler package allows you to submit your playing habits to the external last.fm website.

To get this working involves three steps:

Install the package

Install the package with the familiar:

apt-get install xmms2-scrobbler
Configure the plugin

Store your username and password for last.fm inside a configuration file:

ln -s ~/.config/xmms2 ~/.xmms2
mkdir -p ~/.config/xmms2/clients/xmms2-scrobbler
echo -e "user: username\npassword: password" > \
         ~/.config/xmms2/clients/xmms2-scrobbler/config

The first step is required because otherwise the program will attempt to read configuration settings from ~/.xmms rather than ~/.config/xmms2 which is the current location which should be used.

Install the plugin

Now you need to cause the music-sending script to be launched when xmms2 begins execution:

ln -s /usr/bin/xmms2-scrobbler ~/.config/xmms2/startup.d/

Now you can restart the xmms2 server and your track details will end up online.

(Incidentally if you wish to add me feel free: SteveKemp.)

Daemon Options

As the new xmms2 package is setup in a client-server fashion there are a few things that you can do which you couldn't do previously.

The most obvious thing is that you could have a headless machine piping audio out through a pair of speakers - and this server could be controlled remotely.

By default the server, xmms2d, will create a local socket for communication located in /tmp which will be used by the client(s).

However you can configure the server to listen remotely instead by adjusting the configuration file ~/.config/xmms2/xmms2.conf. For example if you wished to have the server listen upon the network port 9876 you'd add:

 <property name="ipcsocket">tcp://192.168.1.20:9876</property>

Now you can cause the client(s) to connect to your music-daemon over the network by adjusting their configuration files - or specifying the socket in the XMMS_PATH environmental variable.

For example:

export XMMS_PATH=tcp://192.168.1.20:9876
gxmms2 &

Similarly you can update the configuration file for each client to start the server if it isn't already running when they are launched. In the case of gxmms2 you can edit ~/.config/xmms2/clients/gxmms2.conf and ensure it contains:

StartLocalXmms2dOnStartup=yes
Getting OSD back

After a few days I was very comfortable with listening to music, even without a GUI being loaded all the time, but I was really missing the on-screen notification of song-titles. Usually I recognise tracks within a few seconds, but it is nice to have little reminders popup.

Thankfully I knew it was possible to write simple scripts to display screen popups, so I thought it might not be too hard to add this missing functionality.

First of all I made sure that I had the xosd-bin package installed - Since I wanted to use the osd_cat command to actually show the notification.

Once that was done I wrote a simple script I placed in ~/.config/xmms2/startup.d/ - everything executable within that directory is started when the daemon runs, as we've already explained.

My script?

#!/bin/sh
#
#  Display the current track in a popup every time the song changes in xmms2.
#


# previous track title.
prev=''

# Show a message on the screen using OSD.
showMessage()
{
    echo $* | osd_cat  \
        --font='-b&h-lucida-medium-r-normal-*-34-*-*-*-p-*-iso10646-1' \
        --color=red \
        --pos=top \
        --align=right \
        --offset=50 \
        --indent=50
}


# endless loop.
while true; do

    # get current track title.
    current=`xmms2 info 2>/dev/null | grep title | awk -F= '{print $2}'`

    # If we didn't find antyhing then try to get the filename instead.
    if [ -z "${current}" ]; then
        current=`xmms2 info 2>/dev/null | grep 'url =' | awk -F= '{print $2}'`
        current=`basename "${current}"`
    fi

    # if the current track is different to the previous one.
    if [ "${current}" != "${prev}" ]; then
        showMessage "${current}" 
        prev="${current}"
    fi 

    sleep 2
done


This neatly shows the current song title upon my desktop whenever it changes, without an external plugin. (I guess that my shell script could be considered a plugin in its own right, but we'll pretend it isn't!)

It could be tidied up to only display the popup if there is a valid X11 environment to handle the case when the machine is running headless, but otherwise it wasn't a bad job - and it didn't require the need to rebuild any of the existing packages.


This article can be found online at the Debian Administration website at the following bookmarkable URL:

This article is copyright 2007 Steve - please ask for permission to republish or translate.