Use Raspberry Pi as an audio media player controlled remotely

December 6th 2014, 15:39 by Razvan Dubau
Posted in: Home Automation

This tutorial will show you how to use your Raspberry Pi to play music stored on your PC, laptop or on its own storage. You can control the music play from your PC or from an Android and iOS based devices. Of course, for doing this, you have to connect the Raspberry and the other devices in the same network (your home network).

Note: The Pi I’m using for this tutorial is a regular B model running on Debian.

First, let’s connect the Raspberry to Ethernet and to the audio player using the regular Jack 3.5 mm connector. After this we need to access the Pi command line interface through SSH (I use Putty on Windows 7).

Step 1

Install and configure mpd (Music Player Daemon) on Raspberry.

# Install MPD
sudo apt-get install mpd

#Configure MPD
sudo nano /etc/mpd.conf

Search for music_directory and edit the path to “/home/pi/Music”. Next, comment the following line:

bind_to_address "localhost"

by adding a # at the beginning of the line

#bind_to_address "localhost"

Comment some of the lines from audio_output options to look like this:

audio_output {
        type            "alsa"
        name            "My ALSA Device"
#       device          "hw:0,0"        # optional
#       format          "44100:16:2"    # optional
#       mixer_device    "default"       # optional
#       mixer_control   "PCM"           # optional
#       mixer_index     "0"             # optional

Now save the file and exit by pressing CTRL+X and choose to save the changes by pressing “y”.

Restart the MPD process:

sudo service mpd restart

Step 2

Copy a song to Raspberry and play it.

# First let's create the folder we've declared as the music_directory source
mkdir /home/pi/Music

We can use WinSCP to copy files over SSH or we can simply take the SD card out from Pi and copy the song directly on it.
Be careful to copy the mp3 file into /home/pi/Music.

MPD is only a daemon process, which means it doesn’t have any client interface that we can use to play songs. For these actions (play, pause, stop, add song, etc.) we will use a command line client called MPC.

# Install MPC
sudo apt-get install mpc

# Update MPD to make it capable of seeing the new file(s) added to /home/pi/Music
mpc update

# Add your track to MPD playlist
# Note We don't have to specify the full path of the file, because MPD default path 
# is now the music_directory path -> "/home/pi/Music"
# So we will have to specify only the file
mpc add Michael\ Jackson\ -\ Beat\ It.mp3

# Play the track
mpc play

# Info You can see the full list of MPC by using the following command
mpc help

If you get sound from your speakers, it means that you rock 🙂

Step 3

Install MPDroid on an Android device, or MPoD for an iOS based device. Connect the app to your Raspberry IP and you should see the track you’ve copied to Pi memory. You can now play it or pause it from your phone.

Note: Phone and Raspberry must be connected on the same network (your home router).

Step 4

If we want to play music from laptop or PC the things are a just a little complex, but not rocket science.

Let’s say that we are using Windows 7 on a laptop and we have an “ExtraMusic” folder where we keep all of our mp3 files. If we want to play all of these files on Raspberry we have to share them over network and tell Raspberry to read that folder and include all those files into MPD playlist.

Note: The Raspberry and the computer must have the same workgroup

Share the ExtraMusic folder form laptop by:

Right Click on “ExtraMusic” folder -> Properties -> Sharing (tab) -> Share

Select that you want to add Read permissions for Everyone. For some reason if you give only Homegroup permisions you will not be able mount the folder on the Raspberry.

Mount the shared folder on Raspberry

# Create a LaptopMusic folder inside /home/pi/Music
mkdir /home/pi/Music/LaptopMusic

If the laptop has any user and password login, use:

sudo mount -t cifs -o username=Extragsm,password=yourpassword //{Laptop IP}/ExtraMusic 


sudo mount -t cifs -o //{Laptop IP}/ExtraMusic /home/pi/Music/LaptopMusic

Now we have to re-update the MPD

mpc update

If you want to control the MPD from your computer, you have to install a web app on the Pi. There is no client App for Windows or at least, I haven’t found one. I’m working on a PHP API for MPD now. When I’ll finish, I will start to build a web app, so stay tuned :).

That’s it! You can now browse for the laptop music from your mobile phone and play different songs.

If you have any problem trying to do all of these steps feel free to write in the comment box or on Facebook.


Recent Posts