0

I am trying to achieve the following : I want to start a selected song on the rpi from a web interface.

I can play the song through exec

exec("mpg123 /var/www/html/Sounds/Zelda.mp3",$status);

and I can create a list dynamically through /var/www/html/Sounds

<?php
$arr_files = scandir("/var/www/html/Sounds/");
echo "<select name =\"songlist\" size=\"5\">";

foreach ($arr_files as $value){
echo "<option value=\"$value\">$value</option>";
}   
echo "</select>"
?>

How would I go about in order to take the selected song from the html select 'songlist' and then play it using the exec command by clicking a button?

So far, the only thing I am finding is how to play a song on the client, not on the server side.

Hopefully this is clear enough. Please let me know if more information is required.

Thanks.

edit : I would like to say that I am a total newbie with PHP/HTML, so explanations would be welcomed as well.

1 Answer 1

1

You can do it all in one PHP page. I personally would not I would have the processing done in a separate PHP file, but this will get you started

<?php
if(isset($_POST['songlist'])){
    $selected = $_POST['songlist'];
    //exec("mpg123 /var/www/html/Sounds/".$selected);
    echo $selected;
}

echo "<form method='post' name='songlist'>";
$arr_files = scandir("/var/www/html/Sounds/");
echo "<select name =\"songlist\" size=\"5\">";

foreach ($arr_files as $value){ 
    echo "<option value=\"$value\">$value</option>";
}   
echo "</select>";
echo "<input type='submit' name='submit'>";
echo "</form>";
?>
2
  • Thank you for your help. It does get me unstuck. My question is this then : can I use action = "script.php" in the input form to then call a script with the if isset section and then play the song? Is that what you meant when you said to do it in a separate file? Commented Oct 4, 2017 at 12:22
  • yes that is exactly what I mean :D that way when you start styling your form it gets less confusing.
    – Dr.Rabbit
    Commented Oct 4, 2017 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.