Wednesday, December 11, 2013

Raspberry Pi Internet Radio

We have a radio in the office that gets stations sometimes, and fails sometimes.  FM signal is sketchy in my neck of the woods.

So I grabbed one my stagnant Raspberry Pi's and went about a search on Google to find instructions for an Internet Streaming Radio.

Raspberry Pi Wifi Internet Radion Player

I found this site, and although it has some issues with setup it got me going.  Here is my post on what I did using the latest Debian Wheezy for Raspberry Pi and fully updated on Dec. 11, 2013.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get autoclean
sudo apt-get autoremove

My favorite set of commands to get things fully updated.

sudo apt-get install mpd mpc

MPD is the music player deamon.  It does the hard work/heavy lifting.  MPC is the music player client.

sudo shutdown -r now

After a restart everything just works.  Here is a great website with all of the command line tools for using mpc.

MPC - Linux Man Page

My setup is headless and actually sitting in the switch closet connected to an audio cable to the surround sound amp.

sudo apt-get install php5

Below is my php code that I created to control mpc from a webpage.  Why ssh into the system when you can keep the website open and control it from there?

exec("mpc toggle");
exec("mpc stop | mpc clear");
exec("mpc add");
}else if($_POST['s']==2){
exec("mpc add");
}else if($_POST['s']==3){
exec("mpc add");
exec("mpc play | mpc volume 90");
if(isset($_POST['v']) || isset($_POST['vol'])){
if($_POST['v']!=""){$vol = $_POST['v'];}
if($_POST['vol']!=""){$vol = $_POST['vol'];}
exec("mpc volume ".$vol);
<!DOCTYPE html><html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="refresh" content="30" />
<link rel="icon" href="favicon.ico" type="image/x-icon" />
<title>DO Radio</title>
<style type="text/css">
<h1>District Office Radio</h1>
echo "<h3>".exec("mpc -f '%name%' current")."</h3>";
echo "<h2>".exec("mpc -f '[[%artist% ]%title%' current")."</h2>";
<form action="index.php" method="post">
<button type="submit" name="p">Play/Pause</button><br /><br />
$vol = exec("mpc volume");
echo substr($vol,strpos($vol,":")+1);
?></h4><br />
<button type="submit" name="v" value="-10">-10</button>
<button type="submit" name="v" value="-1">-1</button>
<button type="submit" name="v" value="+1">+1</button>
<button type="submit" name="v" value="+10">+10</button>
<br />
<input type="text" name="vol" /><input type="submit" value="Submit" /><br />
<br /><br />
<button type="submit" name="s" value="1">KHTR 104.3</button><br />
<button type="submit" name="s" value="2">The Christmas Station</button><br />
<button type="submit" name="s" value="3">NOAA Weather - Spokane, WA</button><br />

I have actually added a bunch of more radio stations, just grabbed the stream address from this website:

No comments:

Post a Comment