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.

Share/Save/Bookmark


Posted by rjc (87.74.xx.xx) on Mon 19 Mar 2007 at 06:58
[ Send Message ]
There is a program called xmms2-launcher which purpose is to start the daemon.

Regards,
rjc

[ Parent | Reply to this comment ]

Posted by Steve (62.30.xx.xx) on Mon 19 Mar 2007 at 07:04
[ Send Message | View Steve's Scratchpad | View Weblogs ]

Yes, thats right.Also you should be able to kill the running xmms2d daemon by running "xmms2 quit".

Steve

[ Parent | Reply to this comment ]

Posted by rjc (87.74.xx.xx) on Mon 19 Mar 2007 at 07:10
[ Send Message ]
Yes, but you've already mentioned that in the article :^)

rjc

[ Parent | Reply to this comment ]

Posted by Steve (62.30.xx.xx) on Mon 19 Mar 2007 at 07:10
[ Send Message | View Steve's Scratchpad | View Weblogs ]

This is what happens when I get up early!

Steve

[ Parent | Reply to this comment ]

Posted by rjc (87.74.xx.xx) on Mon 19 Mar 2007 at 07:31
[ Send Message ]
I haven't gone to bed yet - too much coffee yesterday I guess ;^) Just finished a round in BfW.

BTW, has anyone got the 'export_playlist' working?

rjc

[ Parent | Reply to this comment ]

Posted by Steve (62.30.xx.xx) on Mon 19 Mar 2007 at 21:09
[ Send Message | View Steve's Scratchpad | View Weblogs ]

I couldn't manage to get "xmms2 mlib playlists_list" to produce anythign, even after adding content with "addall".

Steve

[ Parent | Reply to this comment ]

Posted by Anonymous (206.57.xx.xx) on Sat 31 Mar 2007 at 06:13
Have you saved a playlist yet? Try something like:

#Clear the current playlist
dragon@debian:~$ xmms2 clear
#Add some files - in this case the ones on http://www.mindinabox.com
dragon@debian:~$ xmms2 add miab*.mp3
dragon@debian:~$ xmms2 list
->[0/6] mind.in.a.box - Between Worlds (05:02)
[1/19] mind.in.a.box - Give Me My Life (06:05)
[2/17] mind.in.a.box - Lost Alone 2 (05:48)
[3/18] Mind.In.A.Box - Walking (03:49)

Total playtime: 0:20:44
#See a list of mlib options
dragon@debian:~$ xmms2 mlib
Available medialib commands:
add [url] - Add 'url' to medialib
loadall Load everything from the mlib to the playlist
searchadd [artist=Dismantled] ... - Search for, and add songs to playlist
search [artist=Dismantled] ... - Search for songs matching criteria
query ["raw sql statement"] - Send a raw SQL statement to the mlib
queryadd ["raw sql statement"] - Send a raw SQL statement to the mlib and add all entries to playlist
list_playlist [playlistname] - List 'playlistname' stored in medialib
save_playlist [playlistname] - Save current playlist to 'playlistname'
load_playlist [playlistname] - Load 'playlistname' stored in medialib
playlists_list List all available playlists
import_playlist [name] [filename] - Import playlist from file
export_playlist [playlistname] [mimetype] - Export playlist
remove_playlist [playlistname] - Remove a playlist
addpath [path] - Import metadata from all media files under 'path'
rehash Force the medialib to check whether its data is up to date
remove Remove an entry from medialib
setstr [id, key, value, (source)] Set a string property together with a medialib entry.
setint [id, key, value, (source)] Set a int property together with a medialib entry.
dragon@debian:~$ xmms2 mlib save_playlist miab.pls
dragon@debian:~$ xmms2 mlib playlists_list
miab.pls

Note: If you do a search for a file called miab.pls you won't find one. The reason for this being that your playlists are stored in the ~/.config/xmms2/medialib.db file.
Note: This is with version 0.2DrGonzo-4.1

[ Parent | Reply to this comment ]

Posted by k8to (64.142.xx.xx) on Mon 19 Mar 2007 at 07:54
[ Send Message ]
You may be completely aware of this, but I find the fun part of xmms2 to be the ability to pull things out of the mediadb, instead of just piling them directly from files to playlists.

Eg. "Play the album "below the waste" for me now."

or "Enqueue all the Bola I have in chronological order."

xmms2 offers some support for this, but I prefer to use nyello, another terminal-mode client.

If anyone has an graphical clients they love, I'd love to hear about them.

[ Parent | Reply to this comment ]

Posted by Anonymous (212.254.xx.xx) on Mon 19 Mar 2007 at 08:05
Hi Steve

I have moved away from xmms a few months ago after years of using it as well.
However, I did not try xmms2 but audacious. It is a gtk2 xmms alike audio player with gnome integration. For myself, it is what xmms should have been a long time ago. Finally, a decent file chooser dialog. You may want to have a lock at it.

I'm running debian stable. Audacious is currently in Sid. On the homepage of audacious you find debian packages for Etch too. I recompiled the debian source package of the Etch release to get in working on debian stable. I remember, I had to change some package version number requirements to get it compile on debian stable. Sorry, I can't remember the exact change I had to do.
http://audacious-media-player.org

Regards
Daniel

[ Parent | Reply to this comment ]

Posted by Anonymous (66.232.xx.xx) on Tue 20 Mar 2007 at 11:10
I believe one of the major reasons people used XMMS was the superb little interface. Why xmms2 does not already have a similar gui client confuses me. I use WMUSIC to launch and control XMMS and love the ability to hide XMMS in the background with a middle mouse click. I really don't like gxmms at all and have not found a good gui client yet. I would love to see something with the look and feel of Cplay even.

[ Parent | Reply to this comment ]

Posted by Steve (62.30.xx.xx) on Tue 20 Mar 2007 at 18:53
[ Send Message | View Steve's Scratchpad | View Weblogs ]

You could argue that gxmms2 is that simple GUI...

Steve

[ Parent | Reply to this comment ]

Posted by drgraefy (128.59.xx.xx) on Mon 19 Mar 2007 at 18:56
[ Send Message | View Weblogs ]

Thanks for the update on xmms2, Steve. I'd heard of it's development but hadn't realized that it had made it into etch.

I have been using mpd for a while now, which works on the same client/server model, is able to make connections over the network, and has a variety of clients to choose from. I've been using it on my stereo controller for a while now.

I'm wondering what people think of how xmms2 and mpd compare? Now that xmms2 is in etch, I'll play around with it and see what I think, but I was wondering what other people thought. Does anyone having anything to say about either in a side-by-side comparison?

[ Parent | Reply to this comment ]

Posted by drgraefy (128.59.xx.xx) on Tue 20 Mar 2007 at 14:47
[ Send Message | View Weblogs ]
I came across this nice write-up on xmms2 vs. mpd, for those that are interested.

[ Parent | Reply to this comment ]

Posted by Arthur (66.28.xx.xx) on Wed 21 Mar 2007 at 08:25
[ Send Message | View Weblogs ]
My multimedia keyboard has a "Play/Pause" button on it but xmms2 lacked the toggle function which I have come to rely upon to silence my office when I answer the phone. So I downloaded and compiled xmms2-pp.c (which depends upon libxmmsclient-dev), reconfigured hotkeys to use it, bingo bango bongo my button works again.

Then I found a mailing list thread that suggests that the same functionality has been added to xmms2 upstream and may exist in the unstable branch. packages.debian.org seems to be offline just now, so I can't confirm that. I wasn't willing to wait for it to trickle down into etch anyway.

[ Parent | Reply to this comment ]

Posted by Anonymous (81.88.xx.xx) on Fri 23 Mar 2007 at 07:22
Or you create a 10 line shell script which does the same thing..

#!/bin/sh
FILE=$HOME/.xmms2/playing
if [ -e $FILE ]; then
xmms2 pause
rm -f $FILE
else
xmms2 play
touch $FILE
fi

[ Parent | Reply to this comment ]

Posted by Arthur (66.28.xx.xx) on Fri 23 Mar 2007 at 10:54
[ Send Message | View Weblogs ]
First and foremost, thank you for the time you spent creating and sharing that script. I truly do appreciate it.

I don't have a .xmms2 subdirectory in $HOME, so I'm guessing that it's not necessary and that ~/.xmms2/playing is a flag file created by the (above) script. If this is in fact the case, it's not the same thing. xmms2-pp.c queries the xmms2d daemon to discover the daemon's current mode, so it does the right thing every time it's invoked. The script will only reliably put xmms2d into pause mode if the script was used to put xmms2d into play mode -- if it wasn't, then I'd have to invoke the script twice to get it into sync with the daemon.

If I'm going to be bouncing on the keyboard anyway, I'd just as soon use those keystrokes all at once to compile xmms2-pp.c and know that when I mash the Play/Pause button in the future it's going to do the right thing the first time.

[ Parent | Reply to this comment ]

Posted by mehturt (81.88.xx.xx) on Tue 27 Mar 2007 at 08:19
[ Send Message ]
whatever..
the script works fine for me

[ Parent | Reply to this comment ]

User Login

Username:

Password:

[ Advanced Login ]

Register Account

Quick Site Search