Roaming Media

After you start Icecast, the server configuration should be complete. At this point, start MPD as well. It should hook itself up to the Icecast port, and the logs should be free of errors. Next, an MPD client is needed in order to set up playlists on the server. I use MPDroid for this, an Android variant I use to control playlists from my phone, but there are clients for a wide variety of platforms available via your package manager or from Fire up a client, and add a few songs to a playlist for a test and tell it to play. The Icecast access log (not the MPD logs) should show that a SOURCE has connected, and it should show a 200 return. For example: - - [20/Jul/2011:01:15:03 -0700] "SOURCE / 
 ↪HTTP/1.0" 200 19 "-" "MPD" 424

This shows the incoming connection from MPD on the local box, the current date and time and the fact that this is a SOURCE request as opposed to a player request. It shows the directory accessed "/", the protocol used and the return code "200". This is a great source of verification that the connection between MPD and Icecast is up and working properly, though it does not tell you that any data actually is being passed. For that, you'll need to test it end to end.

To test it, you need a music player that supports Ogg format (or MP3 if you've gone that route). I've chosen Rhythmbox for this example, because it supports Ogg, is popular across a wide range of distributions and has a command-line control system that you can use to start and stop the music as well as set the server URI. Install and launch Rhythmbox (or fire up your favorite player with these features) and set it to play from the Icecast URI. For example, mine is at http://templar:8000/. If you have changed the mount directive in the MPD configuration file to "/music.ogg", the URI would then be http://templar:8000/music.ogg. Either way, when the music player is pointed at this URI, the Icecast access.log file should show something like this:

mj-12 - - [01/Aug/2011:15:28:52 -0700] "GET / 
 ↪HTTP/1.1" 200 1194382 "-" "-" 70

The format for this line is very similar to the one above. The only real difference is that this is a GET request instead of a SOURCE request. Seeing this line in the access logs without a corresponding error in the error log shows you that the media player is requesting the music stream from the Icecast server properly.

If you don't hear music at this time, go back over the setup and check the log files. Check the volume level within MPD, and make sure that the MPD client says a song is playing. Many MPD clients also let you stream music directly, so you can verify that it's working as well.

The next step is to set up your Bluetooth token. In my case, this is my Android phone, but pretty much any Bluetooth device will work. Ranges vary, so placement of the Bluetooth receivers is important to avoid overlap or gaps in the area you're trying to cover.

The Linux package for Bluetooth support is called Bluez. It is widely available and comes as part of most distributions. Install this package if it is not installed on your system already. You don't need to make any configuration changes, because all you need to do is identify that the Bluetooth device is in range. You don't need to pair with it or transfer data between devices. After installing the Bluez package, start the software. Your logs should show that the software started correctly and that it identified your Bluetooth hardware properly.

In order to find the Bluetooth token, it needs to be put into discoverable mode temporarily. Turn that on, and run the following scan command from the command line:

mike@templar:~$ hcitool scan
Scanning ...
	D4:E9:C0:37:00:0D	eris

Make a note of the Bluetooth ID, and be sure that the name field is not blank. It can be anything, but it has to be something. After this step, you can turn off the discoverable mode on the Bluetooth device for increased security. You now have all the information that you need.

The following script checks whether the Bluetooth device is in range and stops or starts the music player based on the result. Replace the SERVER_URI variable with your MPD/Icecast server and the BTADDR variable with your device's Bluetooth ID (this ID comes from the hcitool scan command above):


DBUSADDR=`grep -z DBUS_SESSION_BUS_ADDRESS /proc/*/environ 2> 
sed 's/DBUS/\nDBUS/g' | tail -n 1`

if [ "x$DBUSADDR" != "x" ]; then
  export $DBUSADDR
  echo "Cannot find DBUS Session for Rhythmbox. Please 
be sure the application is running"
  exit 1

NAME=`hcitool name $BTADDR`

if [ -z "$NAME" ] ; then
    `rhythmbox-client --pause`
    `rhythmbox-client --play-uri=$SERVER_URI`

Save this script as /usr/local/bin/ Next, add the script as a crontab entry that runs every minute. This entry must be run as the same user as the user that owns the Rhythmbox process.

Edit the crontab from the correct user:

mike@templar:~$ crontab -e

Add the following line, and then save and exit:

* * * * * /usr/local/bin/

Now, turn on the Bluetooth device (it does not need to be discoverable this time because you already have the address). At the turn of the next minute, the cron script will see the Bluetooth device and then tell Rhythmbox to start playing the music from the MPD/Icecast server. If you move the Bluetooth device out of range, the cron script will no longer see the Bluetooth device and will stop the music.

Rhythmbox, Bluetooth and this cron script must be set up on every machine that you intend to play music for you. If you do it on only one box, only that box will start and stop music as you enter or leave range. If you set up the system on multiple pieces of hardware, it will transition the music for you. When moving out of the range of one server and into the range of another, the music automatically will stop in the room you were in before and start in the room you are in now.

This is just a simple setup for moving media around automatically. Multiple Bluetooth devices could be set up for different members of the house, and a priority system could be put in place. Motion detection using the "motion" package could be set up to differentiate areas of your home further with overlapping Bluetooth. You even could use facial recognition with help from the OpenCV Project. There are many places you can go from here.

Headphones image via



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

roaming media

Roxely samus's picture

At heart, you think that music would not be restricted to headphones?
I and thousands of people hate Guando we conduct a public one and comes with a rude caxinha music without earphone oudido. Nobody is obliged to hear what he hears, then he would have to be educated to use their own handset oara substencia. But his lesson is well guarded and let's see if we can adopt it.
I thank the great audience that this site has and ask administrators the opportunity to leave my site where you realize the work of research and dissemination. My goal is not to create spam, but I publicize my work. Thank you cadeira universitaria

music play

dennisrert's picture

I agree with you grade and gender roxelly. Music in public place is to listen with headphones adestramento de cães


Theras's picture

How does the off-the-shelf open-source programs? You disagree in part to talk about in-room-room. I really liked the article and I will look further. I leave my site Primeira Página do Google

Very interesting

marksen's picture

I will try to use MPD as for your directives.

Thanks for the little tutorial.

Free Dummies Books
Continuous Engineering


  • What continuous engineering is
  • How to continuously improve complex product designs
  • How to anticipate and respond to markets and clients
  • How to get the most out of your engineering resources

Get your free book now

Sponsored by IBM

Free Dummies Books
Service Virtualization

Learn to:

  • Define service virtualization
  • Select the most beneficial services to virtualize
  • Improve your traditional approach to testing
  • Deliver higher-quality software faster

Get your free book now

Sponsored by IBM