Thursday, 29 August 2013

A Simple RPi Music Box

Do you have a Raspberry Pi you are not using, or (like me) have a Pi which is only used infrequently, just to try out ideas?

 

Why not connect it to your stereo and put it to use as a music box.


One of my RPi boards is just used for the occassonal experiment. So I thought I'd load my music files onto an unused 4GB sd card and put this Pi to use.

I guess I have almost 1000 MP3 and OGG files that I prefer to listen to in a random order, as background music. So this was a quick, rainy day project to get them playing through my stereo.

Setting Up The SD Card

I did spend some time trying to get PipaOS to work, but have put that aside, so this is how I'm using Raspbian.

I installed the latest Raspbian Wheezy image in the usual way, using the command line method on my Lubuntu laptop.

While still connected to the laptop I also:-
  •  stretched the sd volume to fill the sd card using gParted
  •  created a music directory: /home/pi/Music
  •  added my music files to the new directory
  •  edited /etc/inittab to auto login by replacing the line that starts "1:2345:respawn:/" with:-
         1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1
  • Created a script called StartMusic.sh which just contains this:-
  #!/bin/bash
  music123 -z -r /home/pi/Music


...which I saved to: /home/pi and made executable via the file manager properties dialog

Finally I opened /home/pi/.bashrc and added this to end of file:-
  bash StartMusic.sh

Note that these edits must be done with root privileges.

Running the RPi Music Box

Now, if you have been following along, when you put this sd card into RPi and boot, it should stop and complain that it can't find music123.

So this is fixed by running:-
  sudo apt-get install music123

Once this is installed, just reboot....job's a good 'un!

With the RPi connected to power and (via the audio jack) to an amplifier, the music box will play all files in a random order.

My RPi Music Box now sits under our TV, on top of the Cambridge Audio amp, and gets powered-on along with all the other media tech in that corner of our lounge.

OK, so there is a 30 second delay before I hear music, but I'll work on reducing the boot time in the coming weeks.

No comments:

Post a Comment