I've successfully install madplay on my router and it run normally if I execute from putty. Now my question is, how I can run it from web interface. currently I've already a php page which display list of mp3 from my song folder.
on putty I can play it with
madplay -Q "folder-name/name-of-my.file.mp3"
So far I create 3 file, index.php, play.php, play.sh
File structures
/www
|- cgi-bin
|- play.sh
|- musicplayer
|- index.php
|- play.php
index.php, used to listing my mp3 file
$dir = "path-to-mp3-folder";
$files = scandir($dir);
$awal = 2;
while($awal < count($files)) {
echo "<tr><td><a href=\"javascript:void(0);\" onclick=\"play('" . $files[$awal] . "')\">" . $files[$awal] . "</a></td></tr>";
$awal++;
}
<script type="text/javascript">
function play(e){var t={lagu:e};$.ajax({url:"http://router-ip/musicplayer/play.php",type:"POST",data:t,success:function(e){},error:function(e){alert("Kesalahan URL")}})}
</script>
play.php, used to hit play.sh inside cgi-bin folder
<?php
header('Content-type: text/html; charset=utf-8');
if(isset($_POST['lagu'])) {
$lagu = str_replace(" ", "\ ", $_POST['lagu']);
exec('killall -9 madplay');
exec('echo "' . $lagu . '" > /tmp/playedmp3');
//exec('sh /www/cgi-bin/play.sh');
exec('curl http://router-ip/cgi-bin/play.sh');
echo $lagu;
} else {
echo "Tidak Ada Lagu Terpilih";
} ?>
play.sh (inside cgi-bin folder)
#!/bin/bash
LAGU=`cat /tmp/playedmp3`
PUTAR="/www/musicplayer/lagu/$LAGU"
killall -9 madplay
nohup madplay -Q $PUTAR &
When I try to access index.php and click on mp3 names, no error, but no mp3 played like if I run it from putty shell.
</div>