I listen to NTS Radio a lot while working, and I’ve got an old Raspberry Pi that doesn’t get much use so I’m going to create a simple net-radio with nothing but an on/off switch. To accomplish this we need to get the Raspberry Pi to automatically play an audio stream on start-up, and also safely shutdown at the flip of a switch.
It’s a good idea to set up the Raspberry Pi so you can access via SSH and do all the work from your normal computer (full guide here. This blog assumes you’re using Raspbian and booting to desktop, the same concepts apply to other setups though.
Step 1 – Firstly we need to get the RaspberryPi playing a remote audio stream, to do this install VLC (updating apt-get first):
sudo apt-get update sudo apt-get install vlc
Once installed check vlc is working correctly (cvlc is the console version of vlc);
If you don’t get any audio (even when it does work it’ll print out some red error logs) the most likely cause is that the wrong output device is configured (default is HDMI), try:
sudo amixer cset numid=3 1
You can switch back using: 0 for auto, 1 for headphone jack, 2 for hdmi.
Step 2 – Play the stream automatically when the Raspberry Pi starts-up. Raspbian will look for an autostart directory on start-up, so we need to create it and add an entry:
mkdir /home/pi/.config/autostart nano /home/pi/.config/autostart/autovlc.desktop
In Nano enter the following:
[Desktop Entry] Type=Application Exec=cvlc http://126.96.36.199:8000/stream
Then restart and hopefully the stream will play:
Note. while testing when the Raspberry Pi restarts you can shutdown VLC by connecting again via SSH and running
Step 3 – Safely turn off the Raspberry Pi from a switch. If you just pull out the USB power supply to turn the device off you risk corrupting Rasbian. To turn off the Pi without using SSH I bought a switch from Mausberry Circuits, the setup guide is here.
Step 4 – build a box…