dtjwov4984 2019-02-05 06:59
浏览 297

OpenWRT基于Web的MP3播放器

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>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮