The Raspberry Pi 2 as an Internet Radio using Mopidy

Recently I got a Raspberry Pi 2, which is said to be 6 times faster than the original Raspberry Pi B. This makes it more suitable for tasks like being a media player.

Getting a full CanaKit Raspberry Pi 2 Ultimate Starter Kit adds many components for experimentation (LEDs, resistors, breadboard, 40-pin ribbon cable, ...etc.). The price was attractive since with Amazon you get free shipping, and therefore it will be cheaper than getting it directly from CanaKit.

Hardware Connections

Obviously, for internet radio to work, the Pi has to be connected to the internet. I used a regular Ethernet connection to the Pi, since there is less variance due to interference in the overall network. Of course, you can of course use the WiFi adapter, if you do not have an Ethernet connection close to the Pi.

For the sound connection, I connected the Pi via HDMI to a receiver that I have. You can connect the Pi to your TV and listen from it if that is what you have.

Operating System

For the operating system, I installed Raspbian Jessie using the default NOOBS on the MicroSD card that came with the kit.

Update The Operating System

First order of things, make sure you do a full software update before you proceed, as follows:

sudo aptitude update
sudo aptitude full-upgrade

Mopidy - a music player

For a music player that can stream content, I found that Mopidy is available for the Pi, and is very well documented.

To install Mopidy, use the following command:

sudo aptitude install mopidy

Once you install mopidy, you need to configure it for Internet streams (internet radio stations), and enable the MPD component for it, so you can control it from another device.

In the file /etc/mopidy/mopidy.conf, add the following section:

[stream]
enabled = true
protocols =
  http
  https
  mms
  rtmp
  rtmps
  rtsp
timeout = 5000
metadata_blacklist =

[mpd]
enabled = true
hostname = ::
port = 6600
password =
max_connections = 20
connection_timeout = 60
zeroconf = Mopidy MPD server on $hostname

Then restart Mopidy like so:

sudo service mopidy restart

Creating Playlists for Radio Stations

Before you can start to stream radio stations, you need to create an m3u file for each stations.

First you need to find the stream for the radio station you are interested in. The best site to use, is vTuner. Once you locate the station you are interested in, the green 'Play' link to the far left will contain the link, but not directly. You need to save the link to a file, and in that file there will be the stream you want.

You can do this by using wget, then inspecting the file that it saves (or the stream it tries to play).

After you have identified the stream, you need to create an .m3u entry under the directory: /var/lib/mopidy/playlists/

The format is quite simple. Here is a template:

#EXTM3U
#EXTINF:0,NAME OF RADIO STATIONS
STREAM

So, for the BBC World Service News in English will be like this:

#EXTM3U
#EXTINF:0,BBC World Service English
http://bbcwssc.ic.llnwd.net/stream/bbcwssc_mp1_ws-einws

Save that to a file in the above directory, and call it something descriptive, and the extension is .m3u, for example: BBC-World-Service-English.m3u.

Then restart Mopidy again, like so:

sudo service mopidy restart

MPD Clients

sudo aptitude install ncmpcpp

If you have an Android phone, you should install MPDoid on it, so you can control the player from your phone.

Streaming Your Internet Radio

Once you have done the above, you can control mopidy from your Android phone, which should be self descriptive.

Or if you are a command line old timer like me, you can control Mopidy from an ssh session using ncmpcpp. Hit F3, and then hit Enter on one of the channels that you have configured. Use + and - to control the volume, and s to stop playing the station.

Enjoy ...

Contents: 

Tags: 

Comments