Control mpc via php

Aus Flipdot

Wechseln zu: Navigation, Suche
This is an simple approach to control mpd via two php scripts running on the Raspberry Pi. "Keep it simple & stupid".

There is "change.php" which is the user interface and passes the user commands via GET to "remote_control.php" and there is a mpd/mpc playlist "radiosender" where the radio stations are selected from.

I assume:

  • Apache is installed on the RasPi
  • mpd and mpc are installed on the RasPi

change.php

shows some soma.fm icons as well as some german radio stations.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
    <head>
        <title>remote control</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    </head>
    <body>

         <style type="text/css">
                  body, input, button, select, option, textarea {
                          font-family: Verdana;
                  }

                  body {
                          font-size: 3.5em;
                  }

                  input, button, select, option, textarea {
                          font-size: 1em;
                  }

                  a:link{
                           color:#EF3824;
                           text-decoration: none
                  }

                  a:visited{
                           color:#EF3824;
                           text-decoration: none
                  }

                  a:hover{
                           color:#EF3824;
                           text-decoration: none
                  }

                  a:active{
                           color:#EF3824;
                           text-decoration: none
                  }
         </style>

<table width="100%" border="0" cellpadding="20" cellspacing="0">
 <tr>
  <td colspan="5"><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Now</a> playing: <br>
          <?php
                 $output = shell_exec("mpc --format '%title%' | head -n 1");
                 echo $output;
          ?></td>
 </tr>
 <tr>
  <td><a href="remote_control.php?radio_control=play"><img src="play.png"></a></td>
  <td><a href="remote_control.php?radio_control=stop"><img src="pause.png"></a></td>
  <td><img src="leer.png"></td>
  <td><a href="remote_control.php?radio_control=volume%20-3"><img src="leise.png"></a></td>
  <td><a href="remote_control.php?radio_control=volume%20%2B3"><img src="laut.png"></a></td>
 </tr>
 <tr>
  <td><a href="remote_control.php?radio=1"><img src="groovesalad.jpg"></a></td>
  <td><a href="remote_control.php?radio=2"><img src="dronezone.jpg"></a></td>
  <td><a href="remote_control.php?radio=3"><img src="lush.jpg"></a></td>
  <td><a href="remote_control.php?radio=4"><img src="u80s.jpg"></a></td>
  <td><a href="remote_control.php?radio=5"><img src="dubstep.jpg"></a></td>
 </tr>
 <tr>
  <td><a href="remote_control.php?radio=6"><img src="secretagent.jpg"></a></td>
  <td><a href="remote_control.php?radio=7"><img src="digitalis.jpg"></a></td>
  <td><a href="remote_control.php?radio=8"><img src="poptron.jpg"></a></td>
  <td><a href="remote_control.php?radio=9"><img src="sonicuniverse.jpg"></a></td>
  <td><a href="remote_control.php?radio=10"><img src="beatblender.jpg"></a></td>
 </tr>
 <tr>
  <td><a href="remote_control.php?radio=11"><img src="missioncontrol.jpg"></a></td>
  <td><a href="remote_control.php?radio=12"><img src="doomed.jpg"></a></td>
  <td><a href="remote_control.php?radio=13"><img src="spacestation.jpg"></a></td>
  <td> </td>
  <td> </td>
 </tr>
 <tr>
  <td colspan="4"><a href="remote_control.php?radio=14">Deutschlandfunk</a></td>
 </tr>
 <tr>
 <tr>
  <td colspan="4"><a href="remote_control.php?radio=15">Deutschlandradio Kultur</a></td>
 </tr>
 <tr>
  <td colspan="4"><a href="remote_control.php?radio=16">Deutschlandradio Wissen</a></td>
 </tr>
 <tr>
  <td colspan="4"><a href="remote_control.php?radio=17">Byte FM</a></td>
 </tr>
</table>

</body>
</html>


remote_control.php

passes the commands of change.php via shell exec to mpc.

<?php

$radio = $_GET['radio'];
$radio_control= $_GET['radio_control'];

// send message to mpc controller of media player daemon via shell command ---------------------------------------------------

  if ($radio <> "")
    {
    $output = shell_exec('mpc play '.$radio);
    }

  if ($radio_control <> "")
    {
    $output = shell_exec('mpc '.$radio_control);
    }

//go back to input form page
  header('location: change.php');
  exit();
  ?>

[Here] are all files including the icons.

Oh, and yes, this is the playlist "radiosender":

http://ice.somafm.com/groovesalad
http://ice.somafm.com/dronezone
http://ice.somafm.com/lush
http://ice.somafm.com/u80s
http://ice.somafm.com/dubstep
http://ice.somafm.com/secretagent
http://ice.somafm.com/digitalis
http://ice.somafm.com/poptron
http://ice.somafm.com/sonicuniverse
http://ice.somafm.com/beatblender
http://ice.somafm.com/missioncontrol
http://ice.somafm.com/doomed
http://ice.somafm.com/spacestation
http://dradio-ogg-dlf-l.akacast.akamaistream.net/7/629/135496/v1/gnl.akacast.ak$
http://dradio-ogg-dkultur-l.akacast.akamaistream.net/7/978/135496/v1/gnl.akacas$
http://dradio-ogg-dwissen-l.akacast.akamaistream.net/7/192/135496/v1/gnl.akacas$
http://streamingserver01.byte.fm:8000/