Roaming Media

Portable music doesn't need to be restricted to headphones. Here's a step-by-step how-to on setting up a music system that follows you around the house like a puppy.

Like many of you, I store all my music digitally on a central server in my home. The problem is when I walk from room to room, my music doesn't come with me. I could carry around an iThingy or put it on my phone, but I'd rather not have to wear headphones, and no matter how awesome they are in their class, tiny phone speakers still are tiny phone speakers. Fortunately, I have a lot of computer hardware lying around from past upgrades, so it was fairly easy for me to come up with some small, older systems for each area of my house. Now, instead of listening to music on a little device, I use a device to tag my location and have the music follow me wherever I go.

The system is easy to build and uses mostly off-the-shelf open-source programs. In addition to the player and control system, you need a way of tagging your location in the house. I use the Bluetooth radio on my phone, but you also could use RFID tags, Webcams with motion detection or facial recognition, or pretty much anything else that will let the system know where you are. For this setup though, I'm assuming you're using a Bluetooth device.

The central piece to this project is a server-based music player. I am using the Music Player Dæmon (MPD), a wonderful server-based system released under the GNU General Public License and available from the repositories of most Linux distributions. Install the software with your favorite package management system. In addition to this player, you need to set up a streaming system. Icecast fulfills this requirement and also is widely available. Install it as well.

Configuring MPD is fairly straightforward. The default file for your distribution is probably very similar to the example below, but you may need to change a few things. The music_directory entry should point to the directory that contains the music files and one bind_to_address should contain the non-loopback name or address of the server. If it binds only to, outside boxes may have trouble connecting to it.

The audio_output section defines where the music goes when it plays. In this case, you want to transcode it to Ogg format and send it to the Icecast server on the same host (although you could run these on different systems if it makes sense for your setup). Within this section, the port and password must match the configuration for the Icecast server, and the mount will define the portion of the URI after the server name. For simplicity, I've left it at /. If you start MPD after this configuration file is set up, it will be missing the Icecast socket to play to, so you need to set that up next. I've added some comments to the configuration below to help document the options there:

music_directory     "/data/arown/files/audio"  #Point this at
the top level of your music directory. If you have more than 
one, a directory of symbolic links may help you.
playlist_directory  "/var/lib/mpd/playlists" #The following
files must be writable. I suggest making the directory owned 
by the user running MPD.
db_file             "/var/lib/mpd/database"
log_file            "/var/lib/mpd/log"
state_file          "/var/lib/mpd/state"

user                "mpd" #This is the user that the MPD
program runs under. I highly suggest making this a nonroot user.
bind_to_address     "templar" #Place your machine name here, not
"localhost" or "" if you want to reach the MPD
server from another machine.

bind_to_address     "/var/lib/mpd/socket"
port                "6600" #This is the client control port for
starting and stopping the MPD player as well as building 
playlists and changing server side volume.
log_level           "verbose"

input {
        plugin "curl"

audio_output {
        type        "shout"
        encoding    "ogg" #This is the media type for the stream, 
if your player wants MP3, use encoding "mp3" and be sure you 
have the proper tools to transcode to MP3 on your box.
        name        "MusicPuppy"          
        host        "localhost" #The name of the box
that the Icecast server is hosted on.
        port        "8000" #The port of the
Icecast server.
        mount       "/"  #This is the part
of the URI after the hostname. I have left it to "/" for
simplicity, but often things like "/music.ogg" are used 
to make it clearer to the user.
        password    "passthis"  #The source password to the
Icecast server. You probably should change this to something 
complex because you'll never have to type it in.
        bitrate     "128" #The bitrate to transcode to. You 
may want to raise or lower this based on your CPU, bandwidth 
or your quality preference.
        format      "44100:24:2"  #This is three variables:
44,100 represents the sample frequency, 24 is the bitwidth, 
and 2 is the number of audio channels. Experimenting here 
may give you better or worse quality, depending on your audio 
hardware and number of speakers.
filesystem_charset "UTF-8"

In order to finish off the server portion, you need to configure Icecast to stream the music it receives from MPD. The sample Icecast configuration file is quite long, but I've cut out the areas that I've changed.

Make sure that the source-password here matches the password from the MPD server. This allows the MPD server authorization to stream music to Icecast:

    <!-- Sources log in with username 'source' -->
    <!-- This password must match the MPD password above -->
    <!-- Relays log in username 'relay' -->

    <!-- Admin logs in with the username given below -->

Be sure that the bind addresses and ports are correct. The bind address can be localhost if the MPD server is on the same box. The port must match the port from the MPD configuration above:


While you're in this configuration file, change the default passwords from "hackme" and "hackmemore" to something more secure, and check the location of the logs for debugging. Mine are in /var/log/icecast, but yours may vary.



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.

Geek Guide
The DevOps Toolbox

Tools and Technologies for Scale and Reliability
by Linux Journal Editor Bill Childers

Get your free copy today

Sponsored by IBM

Upcoming Webinar
8 Signs You're Beyond Cron

Scheduling Crontabs With an Enterprise Scheduler
11am CDT, April 29th
Moderated by Linux Journal Contributor Mike Diehl

Sign up now

Sponsored by Skybot