Wed 26th Sep 2012 at 13:45

Cooking up a Raspberry Pi Music Player (MK-I)

Notice: There is an ArchLinux version of this article that can be found at Cooking up a Raspberry Pi Music Player (MK-||)

IMAG0857.jpg

So I have completed my first attempt at a jukebox / music player to hook up to my Hi-Fi, using the Raspberry Pi. I admit that not much was needed to be done other than installing some software and configuring it (and a bit of a read of this article: http://www.designspark.com/content/raspberry-pi-remote-control-music-player). However, this is only the prototype and there is more work to be done.

I had not come across the Music Player Daemon project in my search for a Linux based music player until researching for the the Raspberry Pi Music player. However, since discovering it, it has become the player of choice. It's a very small daemon yet powerful music daemon and has a command line interface so that any programming language with access to the system() function (or equivalent) could be used to control it. While it doesn't support every audio file under the sun, it supports the major players and offers the ability to use plug-ins.

As my previous post explained, I have had some specific requirements for this player and I think the set up I have created fulfills most of them (although they have grown since this implementation).

 

Getting Started

For this version, I chose to start with an environment I am used too, Rasbian (wheezy) available from the Raspberry Pi's Download page. Once downloaded I simply inserted my SD card into my laptop and executed the following commands: (Sorry, I'm a Linux user, so if you use windows you should check out this page)

    1. unzip 2012-09-18-wheezy-raspbian.zip
    2. sudo dd bs=1M if=2012-09-18-wheezy-raspbian.img of=/dev/mmcblk0
    3. sudo sync

You should be aware that above device path (/dev/mmcblk0) could be different from machine to machine.

Once this has been done, simply pop the SD card out of you computer and slot it into the Raspberry Pi. While you do not need a monitor plugged in at this stage, it will make life a bit easier.

    1. Plug the RJ45 network socket (While WiFi works, it will require some further configuration)
    2. Plug the power source in and wait

When raspi-config automatically loads, as it does on first boot, you should select the following:

    1. change_pass - Change the default password, imortant for security
    2. ssh - Make sure you enable this
    3. boot_behaviour - There is no need to boot into a desktop as we're going to be running it headless
    4. expand-rootfs - This will make use of the entire SD card rather than just the default 2Gb
    5. update - Always good to

It is more than likely you will have to reboot, and to run this command from the command line, just type in raspi-config

Once I found myself at the command prompt, I then proceeded to also:

      1. update the OS using rasbians tool: sudo apt-get upgrade
      2. change the hostname from raspberrypi to raspmusicplayer: sudo echo raspmusicplayer > /etc/hostname

 

Installing and Configuring the Software

The installation is very simple

Music Player Daemon

    1. sudo apt-get install avahi-daemon mpd mpc
    2. vi /etc/mpd.conf and change the following entries
      music_directory        "/var/lib/mpd/music"
      
      #bind_to_address        "localhost"
      
      auto_update    "yes"
      
      zeroconf_enabled        "yes"
      
      zeroconf_name            "Raspberry Pi Music Player"
      

 

Client175

This is a web front-end written in python. I tried multiple options, but finally settled upon this on. If you get the permission correct, you can even edit the mp3 tags.

Furst you will need to download the tarball.

wget http://client175.googlecode.com/files/client175_0.7.tar.gz

Once downloaded:

    1. cd /var/lib/mpd
    2. sudo -u mpd tar -zxvf /home/pi/client175_0.7.tar.gz
    3. vi client175/site.conf and change the following entries
      music_directory: "/var/lib/mpd/music/"

      run_as: "mpd"
    4. vi  /etc/rc.local and add the following line before the exit(0), this will ensure that Client175 is fired up automatically
      /usr/bin/python /var/lib/mpd/client175/server.py &> /var/log/mpd/Client175.log &

 

WiFi

Getting the Raspberry Pi operating wirelessly was crucial for me, as I have no network ports near the Hi-Fi and limited power sockets, so using one of my Devolo dLAN plugs is out of the question. Now, while my wireless dongle was detected and showd up in the output from ifconfig, I could not find a simple way of connecting to the Access Point consistently and stay connected after a reboot. The solution that worked for me was to create a file called /etc/wpa.conf that contained the following:

network={
    ssid="ACCESSPOINT_NAME"
    proto=RSN
    key_mgmt=WPA-PSK
    pairwise=CCMP TKIP
    group=CCMP TKIP
    psk="PASSPHRASE"
}

And the following in /etc/network/interfaces:

auto wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa.conf

Note 1: You should check that the device name is wlan0 and not something else.

Note 2: I prefer using static IP addresses so I know the address I can always reach them at, but the configuration above uses DHCP.

Now we can unplug the RJ45 cable and reboot the raspberry.

 

And Finally the storage

2Gb of space is not going to hold a great deal of music and so I mounted my music folder from another machine. I did this using NFS, however, you could use Samba or any other network file system. I'm not going to go into details on how I mounted via NFS as it was pretty straight forward and it's not my intention for this to be a long term solution. The next phase involves getting a hard disk attached.

 

Conclusion and next steps

While all the above nicely tests the theory, I have a number of issues. Firstly, I am powering the Raspberry Pi from a powered USB hub, one that unfortunately has known problems with back feed and it doesn't look like it will power a usb hard disk.

 

Adding a disk

When I do manage to get a hub that completely works and is able to power a hard disk, as well as the raspberry Pi, I will drop the use of NFS and install a better way of getting the music onto the disk.

 

Building a case

The intention is to build a custom case for it, and I quite like the idea of playing with the GPIO to produce some sort of led effects, be it a visualisation of the music or just colours to make it look like an old school jukebox system.

 

Wired controller

It would be quite nice if I didn't have to use my phone to control the player. While I don't mind, the inlaws have shown their interest in having something like, but they do not have flashy phones and would rather just switch it on and plug a usb stick and off it plays.

I have seen some C code that allows you to control MPD with a wheel mouse and will be picking the code apart to see if I can use my multi-button wheel mouse to allow more functions.

 

LED Display

To be honest, this may push the price a bit high, but I think it would be quite nice to attach something to it to display the status of MPD

 

Bluetooth

Why do I want to enable bluetooth? The answer is simple. I have a bluetooth speaker that I'd like to output to.

 

ArchLinux

Rasbian is okay. and as it is debian based I am very familiar with it. However, it is quite slow. ArchLinux appears to be a lot more streamlined and has a far quicker boot time. See Cooking up a Raspberry Pi Music Player (MK-||) for details.

 

 

This site uses cookies, please read my cookie policy.