02-26-2019, 10:28 AM
Here's how I do it. Two files:
autoamp.sh
autoamp.service
Put the first in your home directory. Put the second in /etc/systemd/system/
Then run
sudo systemctl enable autoamp.service
sudo systemctl daemon-reload
sudo systemctl start autoamp.service
The 1st file, which I borrowed from someone (thanks!), polls the /proc/asound/card0/pcm0p/sub0/status virtual file (this works for my set-up, you might need to alter which file it polls depending on yours) for the text "RUNNING". This only appears when sound is playing. If it finds it, then it changes the state of your specified GPIO pin (in my case 23). If it doesn't find it, then no change. If it did find it, but then it doesn't anymore, then the state is changed as well. There's a counter in there for a delay on this change.
Hope this helps.
autoamp.sh
autoamp.service
Put the first in your home directory. Put the second in /etc/systemd/system/
Then run
sudo systemctl enable autoamp.service
sudo systemctl daemon-reload
sudo systemctl start autoamp.service
The 1st file, which I borrowed from someone (thanks!), polls the /proc/asound/card0/pcm0p/sub0/status virtual file (this works for my set-up, you might need to alter which file it polls depending on yours) for the text "RUNNING". This only appears when sound is playing. If it finds it, then it changes the state of your specified GPIO pin (in my case 23). If it doesn't find it, then no change. If it did find it, but then it doesn't anymore, then the state is changed as well. There's a counter in there for a delay on this change.
Hope this helps.