Wednesday, December 12, 2012

Music and radio on Raspberry Pi/Gentoo

This is a follow-up to my last post about Gentoo on the RPi.
I pointed out in that post that I was having difficulties getting music to play in Gentoo.
Up to that point, I had managed only to play some .wav files using aplay.
But, neither .mp3, .ogg or .flac files produced any music.
When I tried, I got errors of this type:

play FAIL formats: no handler for given file type `mp3'

In fact, this is a feature of Gentoo. If you want something, you have to specify it with the USE flags before the compile.

So, I compiled the SoX music player using these flags


sudo USE="flac mad mp3 vorbis ogg alsa" emerge -av sox

[ebuild   R    ] media-sound/sox-14.3.2-r1  USE="alsa flac* mad* ogg* openmp png (-amr) -ao -debug -encode -ffmpeg -id3tag (-ladspa) -oss -pulseaudio -sndfile -static-libs -wavpack"


and this worked perfectly with .mp3, .flac, .ogg and .wav files.

OK, so I have music. But now I want streaming radio, too.

This very early thread seemed to provide everything I needed using the music player daemon (mpd) and its client mpc.
So, I emerged mpd with the same USE flags as I had used earlier for SoX and this worked fine.
Next, I needed the client mpc.
Unfortunately, during the compile (or possibly during the mpd compile/install) my compiler seems to have broken (armv6j-hardfloat-linux-gnuabi-gcc-4.5.4-1).
This has seriously messed up my install and nothing else can be installed.
My only hope, other than a re-install, is to find a suitable binary or cross-compile the compiler on my Desktop Gentoo install.

Nevertheless, I did manage to get streaming radio working fine on my Raspbian install.
The steps were as follows:

1. sudo apt-get install mpd
2. sudo apt-get install mpc
3. Create a script with the following input:


#!/bin/bash
cd /home/paul/
rm *.pls
wget http://www.bbc.co.uk/radio/listen/live/r4_aaclca.pls
grep "File1=" r4_aaclca.pls > streamaddr
mpc clear
mpc add $(sed 's/File1=//g' streamaddr)
mpc play

The script is shamelessly copied from the above thread.
Give the script a short name (mine was r4), make it executable, and copy to /usr/bin.
Now, to play my favorite radio station (BBC, Radio 4), I merely need to hit Alt-F2 and type in r4 (or you can just type r4 in a terminal) and I have radio in less than 2 seconds.

So, no reason to believe this wouldn't have worked in Gentoo on the RPi.

To shutdown the radio is a little more complicated.
You can run find the PID of the mpd process (ps -e or similar) and then
sudo kill PID
Alternatively, you can type 
sudo killall -9 mpd

Unfortunately, r4 won't start a second time ("connection refused" error) without a reboot.
When I find how to fix this, I'll edit this post.


No comments:

Post a Comment