Skip to content


Music Networking with XMMS2, Icecast2 and Last.fm

In the last few months I haven’t found much time to listen to music, but I decided this needs to change and I should finally dust off my old music library. About two years ago I signed up for last.fm, the social music network that makes it easy to discover new music and connect with other music fans. I used their software on my Windows box, but I rarely work with this system anymore. After adding several other computers and laptops to the household I didn’t bother with shared music folders and last-fm anymore. This was then.

Today I’m trying to setup a server that makes my music available to any of my computers and operating systems in the LAN, and possibly even outside the local network. At the same time I would like to add last.fm again, however, not linked to each individual player, but only once, to the music server.

musicnetwork

I stored my music files on an external network drive. This music folder is a Samba share and accessible from other computers on the network.

VLC is known for its network streaming features and I wrote a little about it back in May. While I use it occasionally to stream videos from one computer to another I was looking for a solution that could work better as a permanent configuration, well-suited as a music library. That’s how I stumbled upon the X-platform Music Multiplexing System 2, XMMS2.

XMMS2

XMMS2 is a client-server music platform which can be controlled via command line but also through a variety of other interfaces available on Linux, Windows as well as Mac. It allows you to play and manage your music collection on a local server or across the network. It is free, open-source and extensible with a growing number of plugins.

On my Ubuntu system, it was just a matter of seconds to install XMMS2. Ubuntu’s repositories already include everything you might need. I browsed the Synaptic package manager for…

  • xmms2, the core application with server and command line client interface.
  • xmms2-plugin-smb, a Samba transport extension I needed to get access to my music share.
  • xmms2-scrobbler, used to submit data to Last.fm
  • esperanza, a simple player, xmms2-client and graphical user interface
  • xmms2-plugin-flac, to support the flac-format
  • xmms2-plugin-mp4, to support the mp4-format

XMMS2′s command line interface is very easy to use thanks to its legible commands and parameters, just to mention a few:

  • To start the server: xmms2-launcher
  • To quit the server: xmms2 quit
  • To add some music: xmms2 add /home/gerrit/Music/track.mp3
  • To add a folder recursively: xmms2 radd /home/gerrit/Music/electronic/
  • To add some music from my samba-share: xmms2 add smb://username:password@edmini/music/electronic/track.mp3
  • To list the contents of the current playlist: xmms2 list
  • To play: xmms2 play
  • To stop playback: xmms2 stop

If the server is already running and you install new plugins, you may have to restart it before you can use the plugin. You can stop the server with xmms2 quit, or if that doesn’t work for some reason:

  1. find the process-id with ps aux | grep xmms2d and
  2. kill the process with sudo kill processid.

XMMS2 makes it easy to organize music in playlists:

  • xmms2 playlist list lists all available playlists
  • xmms2 playlist create myplaylistname creates a new playlist
  • xmms2 playlist load myplaylistname loads an existing playlist
  • xmms2 playlist active shows which playlist is currently active

With a separate set of media library commands you can also keep track of your artists, track and album titles, cover images, etc. To display a list of related commands: xmms2 mlib. To search for an artist: xmms2 mlib search artist:"Boards*". Standard wildcard characters like ‘*’ and ‘?’ are supported, too. It’s probably easier to use these mlib functions from an XMMS2 client software other than the command line. With a player like Esperanza you will find an easy-to-use graphical user interface for command line parameters.

To make the XMMS2 daemon reachable from other computers I added a tcp-socket to the configuration nano ~/.config/xmms2/xmms2.conf

unix:///tmp/xmms-ipc-gerrit;tcp://

More details on remote machines can be found in the FAQ. The default port is 9667. After restarting the xmms2d daemon I was ready to test my configuration from the other computer, a Windows system.

I installed the Windows built of XMMS2 and Esperanza which I found here, puzzle’s win32 folder. I had to make sure to use the version that matches the version of my server, in this example it was XMMS2-DrLecter.

I defined the following environment variable XMMS_PATH = tcp://192.168.1.43:9667 to let XMMS2 know where to find my music server.

The command-line version of XMMS2 works great on Windows, but I was still experiencing some problems with Esperanza (downloaded Esperanza-0.3.exe) which exited with a runtime error. Whenever I tried to launch Esperanza on Windows, the server responded with “Client ‘Esperanza’ with bad protocol version (1, not 11) connected”.

This looked like a similar conflict I experienced with the wrong XMMS2 version before, so I looked for another version. I found the DrLecter built Esperanza4-DrL.7z here. This version works great.

Esperanza

Now I was ready to play, stop, and control my XMMS2 daemon from my remote computers, may it run Windows or Ubuntu. However, this configuration didn’t actually stream music from my server to the remote machine. It only served as a channel to remote control the server’s playlist. The music was still played nowhere but on the server system.

Icecast2

Icecast2 is a streaming server, a package that will allow you to setup a simple Internet radio station. It, too, is readily available in Ubuntu’s repository and can be installed via Synaptic. After installation I updated two configuration files: sudo nano /etc/icecast2/icecast.xml

There I defined some passwords where the default was marked with ‘hackme‘. I also changed the ports to 9600/9601. No particular reason, other than having the Icecast2 ports relatively close to the XMMS2 default port. You can choose any port there. More details in the basic setup help. I left all the other settings alone and edited sudo nano /etc/default/icecast2 to set ENABLE=true. After that I could start Icecast2 with /etc/init.d/icecast2 start.

The Icecast admin-page should now show up with the url http://localhost:9600. But there still is no music to stream. In the next step I linked XMMS2 to Icecast, using the…

xmms2-plugin-ices

As part of the Ubuntu repository it was installed in a matter of a few seconds. It needed to be configured in the ices section of nano ~/.config/xmms2/xmms2.conf.

Make sure you stop the daemon before you make any changes, otherwise they might not be visible next time you restart. If you can’t find an ices section after a fresh installation, you can let XMMS2 and the plugin set a default section up for you. Try restarting the daemon. In the ices section I just set the password and portnumber (9600) to match what I defined for Icecast2 earlier. See also the XMMS2 wiki.

This didn’t want to work in the beginning. I received error messages about insufficient permissions. I think this was caused by the fact that XMMS2 and the plugin both ran as gerrit, Icecast2, however, as root. To solve this problem I copied the Icecast configuration (icecast.xml and admin, web-folders) to my home-folder, and changed the owner of all these files.

chown -hR gerrit ~/.icecast
sudo nano /etc/default/icecast2

Now I had to point the daemon to the new folder:

CONFIGFILE="/home/gerrit/.icecast/icecast.xml"

# Name or ID of the user and group the daemon should run under
USERID=gerrit
GROUPID=gerrit

Almost done. There still was a warning about the error- and access logfiles in /var/log/icecast2/. To solve this I had to change the owner of the log-files chown gerrit /var/log/icecast2/* and restart Icecast2 /etc/init.d/icecast2 start

Now I could set the output plugin to ices and start the playback with

xmms2 config output.plugin ices
xmms2 play

The radio stream is reachable with the following address for favorite media player: http://localhost:9600/stream.ogg.m3u, or http://192.168.1.43:9600/stream.ogg.m3u

VLC

Having turned the output to Icecast, you won’t be able to hear any music on the server, unless you open the stream. If you want to return to the standard sound output, use the following command:

xmms2 config output.plugin alsa

At this time, both output plugins can’t be activated together to hear music both on server and remote computer. You can only hear music if you connect to the Icecast server. The XMMS2 FAQ explains:

The possibility of multiple outputs involves a nontrivial solution. The biggest problem is keeping all of the outputs in sync with each other. Each output must pull audio data from a buffer following the last decoder or effect plugin in the xform chain at a rate determined by the samplerate of the underlying device. For example, streaming audio will have an exact bitrate since no actual audio hardware is used for obtaining audio data, but a soundcard’s samplerate may vary by a few Hertz with temperature, components, and voltage. We end up with an ever growing buffer (if the buffer holds data longer for slower outputs) or dropped samples (if the data is destroyed after the faster output has read it).

There are also smaller issues like that the xmms2 daemon takes into account the delays caused by the output plugin when showing the current playtime, but if there are multiple outputs these delays can vary. So one of them would have to be defined as a primary output to keep this feature in use.

Current plan to resolve the aforementioned problem with concurrent output and stream sourcing is to make it possible for effect plugins to keep a constant input format and stay alive through song changes. That way they can draw the data from the stream itself and it won’t have synchronizing problems because the whole chain is still simple and one-dimensional.

The current configuration works great now. I have a server that provides a stream of music. This stream is accessible from all other computers, and I am able to control this Internet radio stream using XMMS2 and Esperanza if needed, from any other computer running Linux or Windows.

At this point I could probably stop and let it be, but I want to integrate some web-services and social media tools. While I’m mostly just experimenting with a new range of Internet applications, I’m also interested in sharing my music favorites and creating some personal charts of my highlights, the most frequently played tracks, the most important artists, etc. A great tool to link my local music adventures to the web 2.0 world is last.fm.

Last.fm

Last.fm

To make my XMMS2/Icecast2 server talk with Last.fm I installed the xmms2-scrobbler plugin…as usual, from the standard Ubuntu repository. To configure this plugin I followed the instructions I found at sudosys.

The XMMS2 configuration is stored in ~/.config/xmms2, but the plugin tries to read it in ~/.xmms2. To work around this, I created a symlink ln -s ~/.config/xmms2 ~/.xmms2

Next, I created a new directory for the plugin configuration and created a config file with my credentials:

mkdir -p ~/.config/xmms2/clients/xmms2-scrobbler
nano ~/.config/xmms2/clients/xmms2-scrobbler/config

added

user: MY_LASTFM_USER
password: MY_LASTFM_PASS

I created another symlink for the actual xmms2-scrobbler script, so it gets executed when I launch XMMS2.

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

After restarting XMMS2 your music will show up on your last.fm profile.

FacebookContinuing from there you can expand your network by adding other services that access last.fm for your music statistics. On Facebook you can use a last.fm application to display your charts on your page or profile.

You can also integrate your last.fm data into your WordPress site with the LiveStream plugin. There is much more you can do, especially if you write your own applications, but this is how far my own configuration goes right now.

I hope you found any of these notes use- or helpful. As usual, please let me know if I forgot something or made a mistake somewhere. :]

Posted in Multimedia, Software.

Tagged with , , .


4 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. capeone says

    Many thanks for help how to configure scrobbler.

  2. Belvidere says

    No doubt, I set up icecast a couple of years or so ago, but without the ability to change songs or anything it wasn’t very useful. I did use it to stream the input from the aux in on my sound card, from my sirius receiver, so I could listen to Howard at work before they started streaming his channels on the sirius internet thing. I’ll definitely be using these instructions soon to give it another go. Great article, thanks!

  3. awessendorf says

    Way over my head but none the less VERY impressive. I am glad you got it working! :-)

Continuing the Discussion

  1. Liberando tu mente linked to this post on November 1, 2009

    Tutorial servidor XMMS2 + Icecast2 en Ubuntu…

    La verdad es que he dejado al blog bastante solitario, solamente me he dedicado a ver si había comentarios, y encima parece que hay un problema con el sistema de notificación por email, porque no me ha llegado ninguna notificación, y hay comentarios……