在网页上单击 link 时在服务器上执行音频播放器

Execute audio player on server when link is clicked on web page

我似乎不知道如何在我的网络服务器上打开 mp3 文件。 如果我只是 href 歌曲(下面的代码),它会在我访问它的客户端上打开它。 即使我从另一台设备访问 html 页面,我也希望歌曲在网络服务器上播放。

<!DOCTYPE html>
<html>
<body>
<a href="Song.mp3">Song</a>

</body>
</html>

我该如何解决这个问题? 我正在使用 Raspberry Pie、Apache、VLC(播放 mp3) 感谢您的支持:D

试试这个:

index.html:

<a href="/script.php">Song</a>

script.php:

<?php exec('export DISPLAY=:0; cvlc songs/Song1.mp3'); ?>


编辑:

inotifywait 的解决方案 CPU 消费友好:

Php:

<?php 
    shell_exec('cat Song1.txt');
 ?>

Bash:

touch Song1.txt  
while  [ -f run.txt ]
do
    inotifywait --event=close_nowrite Song1.txt
    cvlc --play-and-exit songs/song.mp3
done

因为我无法直接执行命令,所以我必须创建一个脚本来对创建的文件做出反应。

<?php 
    shell_exec('touch Song1.txt');
    ?>

Song.sh :

while  [ -f run.txt ]
do
if [ -f Song1.txt ];
then  
        cvlc --play-and-exit songs/song.mp3
        rm -f Song1.txt
fi
done