Hi,
please could you provide guidance how to call a custom python script when moode plays music as well another one that would be called when music stops? - I want to control a relay by the RPI GPIO that would be switching the amplifier on and off.
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.
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.
Thanks! Great, this works and I especially like that it is independent way how to control the relay (on moOde or anything else).
You may use the cat to help you show what the sound card output is
cat /proc/asound/card0/pcm0p/sub0/
or other file, depending on the sound card that you are using.
If others follow this procedure, you will most likely further need to make the script executable (first line below) or even run it always as root - second line (GPIO needs to be called as root, or at least it is the simplest way that I found to do that):