1

Got my PI for xmas and I want to turn it into a web based music player.

As a test I run these commands: First, make sure it's using the 3.5mm jack:

sudo amixer cset numid=3 1

Then play the music:

sudo mpg123 /files/music/Martin_Garrix_Animals.mp3

Doing this directly into the console works.

If I try doing it via PHP

<?php

//using either of these, tried with sudo before each command
exec("mpg123 ../files/music/Martin_Garrix_Animals.mp3");
shell_exec("mpg123 ../files/music/Martin_Garrix_Animals.mp3");

?>

I get nothing, I'm not sure if it's due to permissions?

Any ideas?

Thanks

S

  • Try playing a long audio file and see if mpg123 starts using top – Jervelund Dec 30 '13 at 11:28
  • Add echo and you'll see the console output when you run your php script. echo exec("mpg123 ../files/music/Martin_Garrix_Animals.mp3"); – Andrew Surzhynskyi Dec 30 '13 at 11:32
  • Use ps aux | grep php to find out as which user is your PHP running as. Then add this user to audio group using usermod -a -G audio <username> (substiting <username> with proper user, it will probably be www-data). Also try changing relative paths to absolute ones. – Krzysztof Adamski Dec 30 '13 at 11:35
  • @Dead133 this is the output i get when using shell_exec.jackdmp 1.9.9 Copyright 2001-2005 Paul Davis and others. Copyright 2004-2012 Grame. jackdmp comes with ABSOLUTELY NO WARRANTY This is free software, and you are welcome to redistribute it under certain conditions; see the file COPYING for details JACK server starting in realtime mode with priority 10 control device hw:0 control device hw:0 – Steven Yates Dec 30 '13 at 11:46
  • @KrzysztofAdamski the result of that is: pi 2881 0.0 0.1 3544 808 pts/0 S+ 11:45 0:00 grep --color=auto php. So i ran "sudo usermod -a -G audio pi" and tried again but same thing. No sound. – Steven Yates Dec 30 '13 at 11:47
1

Check the permissions of /dev/snd/ to ensure the user that PHP is running as has the correct access rights.

1

The Problem can be solved by adding /usr/bin/mpg123 into /etc/sudoers like:

sudo nano /etc/sudoers

and add the line

ALL     ALL = NOPASSWD: /usr/bin/mpg123

than you can use in php

shell_exec("sudo -b /usr/bin/mpg123 YourFile")

good luck!

0

Try using the absolute path when running from PHP, as it may well be unable to find the music files with the relative path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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