Internet radio stations can be streamed on a Raspberry Pi using simple terminal commands and Mplayer. This post shows what is required and how.
Table of contents
Introduction to streaming internet radio on a Raspberry Pi
Internet radio stations can be streamed on a Raspberry Pi and the Raspberry Pi OS (formerly known as Raspbian). The terminal or Bash scripts will be used for the streaming commands. PuTTY can also be used.
This post will be using Radio Sonder Grense (RSG), as an example, but other radio stations can also be used. A few additional radio stations are also mentioned.
Mplayer will be used to play internet radio. While some media players may need PLS or M3U files, Raspbian’s Mplayer will need ‘direct stream links’ (a link to the actual streaming server) or ASX files (advance stream director files which store playlists).
Using PLS, ASX or M3U links is apparently the best, as these links are usually permanent and will not change. Direct stream links can vary based on individual server availability. The most up to date link will be required.
- Get the Raspberry Pi 4B 4GB Starter Kit from Amazon.com or BangGood
- Get the Raspberry Pi 4B 8GB Starter Kit from Amazon.com or BangGood
Streaming internet radio on a Raspberry Pi
Assumptions and requirements
A fully set up Raspberry Pi running the latest update of the Raspberry Pi OS (Raspbian) connected to the internet via Wi-Fi or an Ethernet cable. A keyboard and screen output or PuTTY can be used. Audible audio output to speakers or via HDMI is required.
The streaming services of RSG and Antfarm Internet Radio will be used, but similar radio station streaming services can be used.
Audio player software
For this project, we will be using MPlayer to stream internet radio on the Raspberry Pi. MPlayer is a free, open-source video and audio player for all major operating systems. It can play various file formats including .mp3 and audio streams.
The Raspberry Pi OS might not come with MPlayer pre-installed. The following
apt-get terminal command can be used to install mplayer:
sudo apt-get install mplayer
Out of the box, MPlayer will work just fine for audio streaming. It works simply by using
mplayer in the command line. Output can be tested by the following command:
This tells MPlayer to play the pathed .wav file through your default audio hardware settings. Like with some other ALSA-friendly audio players, the audio hardware can also be set by using the following:
mplayer -ao alsa:device=hw=0,0 /usr/share/scratch/Media/Sounds/Vocals/Singer2.wav
mplayer -ao alsa:device=default /usr/share/scratch/Media/Sounds/Vocals/Singer2.wav
On the RSG home page, the following links are available under different devices:
http://radio.antfarm.co.za/cdn/clients/sabc/rsg/rsg_22.asx http://radio.antfarm.co.za/cdn/clients/sabc/RSG/mplayer.asp http://radio.antfarm.co.za/cdn/clients/sabc/RSG/listen.plsv rtsp://126.96.36.199:1935/rsg/RSG-Powered_by_Antfarm.stream http://radio.antfarm.co.za/cdn/clients/sabc/RSG/player.asp?id=65
From this list, one can see that there are two direct stream links (.mp3 & .stream) and one ASX file. The .mp3 link worked for me. To use a stream link:
mplayer -ao alsa:device=hw=0,0 http://188.8.131.52:9032/;listen.mp3
to work with an ALSA device.
While the stream is playing, the p keyboard key can be used to pause, m to mute and q to quit the stream playback.
MPlayer can also be stopped externally from a logged-in device by using the
sudo pkill -f mplayer terminal command.
MPlayer also has a nice playlist function. This post won’t go into any detail, but it might be needed if the normal commands do not work. MPlayer’s
-playlist flag needs to be used for ASX files. If the playlist flag is used, the address becomes quoted:
mplayer -playlist "http://radio.antfarm.co.za/cdn/clients/sabc/rsg/rsg_22.asx"
Although I personally could not get it to work, it seems like playlisting is also needed for ASP links — maybe you come across other internet radio links that might need it.
Other known radio station links
DEF CON Radio FM
or see http://somafm.com/defcon/directstreamlinks.html for their updated list.
Radio Landsberg International
or see http://www.radiolandsberg.international for their website.
KDFC (California Classical)
or see http://www.kdfc.com/pages/15744898.php for their updated list.
mplayer -playlist "http://radio.antfarm.co.za/cdn/clients/classic/classicfm_22.asx"
or see http://www.classicfm.co.za for their website.
This post showed how to stream audio on a Raspberry Pi using Mplayer and terminal commands.
Please share your favourite radio station’s streaming address in the comment section below.