<?php
//------------------------------------------------------------------------------
$Playlist = "/home/pi/playlist/radio01.m3u";
// m3u in /HOME/PI/PLAYLIST ablegen!!!! sib 04.06.2021
$MaxRowCounter = 3 * 2; //Spalten Anzahl! Hier: 3Spalten! * 2(Konstante!)

//------------------------------------------------------------------------------
require_once("functions.php");
exec("mpc playlist ", $output, $return_var);
//var_dump($output);
$r_output=sizeof($output);

//echo $r_output."<br/>\n";

if ($r_output <1) {
	exec("mpc load ".basename($Playlist, '.m3u'), $output, $return_var);
	};


?>
<!--<html>--!>
<!doctype html>									<!-- TEST--!>
<html lang="de">								<!-- TEST--!>
<head>
    <meta charset="utf-8">							<!-- TEST--!>
    <meta name="viewport" content="width=device-high, initial-scale=0.5">	<!-- TEST--!>
<title>Internetradio</title>
<script type="text/javascript" src="./js/jquery.min.js"></script>
<script type="text/javascript">
  function control(command){
    $('#result').load("functions.php?cmd="+command);
  }
  function sender(num){
    $('#result').load("functions.php?sender="+num);
  }
  function currentTitle(){
    $('#currentTitle').load("functions.php?cmd=current");
  }
  function loudness(){
    $('#loudness').load("functions.php?cmd=control('volume')");
  }
  var intervalID = false;
  function init() {
    if (intervalID) { clearInterval(intervalID); }
    intervalID = setInterval(currentTitle, 500);
  }
</script>
</head>
<body onload="init();">
<font size='3' face='Arial'><b>
<p>
<a href="#" onclick="control('stop');">Stop</a> &#8226;
<a href="#" onclick="control('leiser');">Leiser</a> &#8226;
<a href="#" onclick="control('lauter');">Lauter</a> &#8226;

<!--<a href="#" onclick="currentTitle();">Spiel aktuell</a> &#8226;-->
<!--a href="#" onclick="control('volume');">Vol.</a><br> <!--&#8226-->
</p>
<!--<center>-->
<table border="1" cellpadding="1" cellspacing="0" bordercolorlight>
<?php
$StreamFile = file($Playlist);
$Counter = 0;
foreach($StreamFile AS $line_num => $line) {
	$line=str_replace("#","",$line);
	if ($line_num % 2 == 1) { 
	    echo "<font size='1' face='Arial'>";
	    echo "<td><a href='#' onclick='sender(".$SenderCount.");' title=".$SenderCount.">".$SenderCount."-".$Sender."</a></td>\n";
	//    echo $SenderCount. "--". $Sender;
	}
	if ($line_num % 2 == 0) { 
	    $Sender = $line;
	    $line_ptr=$line_ptr + 1;
	}    
	$SenderCount = $line_ptr;
	$Counter++;
	if ($MaxRowCounter == $Counter) { $Counter = 0; echo "</tr>\n"; }
}
if ($SenderCount <> $r_output){
	exec("mpc clear", $output, $return_var);
    	exec("mpc load ".basename($Playlist, '.m3u'), $output, $return_var);
    }

?>
</table>
</center>
<div id="currentTitle"></div>
<div id="result"></div>
<!-- <p><div id="loudness"></div></p><br>    CHECKEN! 15.06.2018 -->
</body>
</html>