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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog