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 http://mpd.wikia.com/wiki/Clients. 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:
127.0.0.1 - - [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
mount directive in the MPD configuration
"/music.ogg", the URI would then be
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
#!/bin/bash SERVER_URI="http://templar:8000/" BTADDR="D4:E9:C0:37:00:0D" DBUSADDR=`grep -z DBUS_SESSION_BUS_ADDRESS /proc/*/environ 2> ↪/dev/null| sed 's/DBUS/\nDBUS/g' | tail -n 1` if [ "x$DBUSADDR" != "x" ]; then export $DBUSADDR else echo "Cannot find DBUS Session for Rhythmbox. Please be sure the application is running" exit 1 fi NAME=`hcitool name $BTADDR` if [ -z "$NAME" ] ; then `rhythmbox-client --pause` else `rhythmbox-client --play-uri=$SERVER_URI` fi
Save this script as /usr/local/bin/musiccontrol.sh. 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/musiccontrol.sh
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 Shutterstock.com.
- Brent Laster's Professional Git (Wrox)
- Own Your DNS Data
- Smoothwall Express
- Machine Learning Everywhere
- Bash Shell Script: Building a Better March Madness Bracket
- Returning Values from Bash Functions
- Understanding OpenStack's Success
- Simple Server Hardening
- From vs. to + for Microsoft and Linux
- Tech Tip: Really Simple HTTP Server with Python