skip to Main Content

I can’t seem to figure out how to open an mp3 File on my Webserver.
If I just href the Song (Code below) it opens it on the Client I am accessing it from.
I want the Song to play on the Webserver even if I access the html page from another Device.

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

</body>
</html>

How do I solve this?
I am using a Raspberry Pie, Apache, VLC (to play mp3)
Thanks for your support 😀

2

Answers


  1. Chosen as BEST ANSWER

    Because I couldn't execute the command directly I had to create a script which reacts to created files.

    <?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
    

  2. Try this:

    index.html:

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

    script.php:

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


    Edit:

    Solution with inotifywait which can be CPU consumption friendly:

    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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search