I use ALSA. I want to prevent PC to suspend while a sound is played. I use this bash code to run a screen locker and a suspend command:
# Run a screen locker.
#xautolock -time 5 -locker slimlock &
# Run suspend
#xautolock -time 6 -locker 'systemctl suspend' &
I want to detect that sound or video is played and prevent PC to suspend. For instance a pseudocode:
if (video is not played)
{
run a screen locker
}
if (sound is not played and video is not played)
{
run suspend command
}
How to detect that a sound or a video is playing with a command line utility?
Run the lspci command in the Terminal to find out what sound card you have: Go to the Activities overview and open a Terminal. Run lspci as superuser; either type sudo lspci and type your password, or type su, enter the root (administrative) password, then type lspci.
Check if any /proc/asound/card*/pcm*/sub*/status
file contains state: RUNNING
.
I use this:
pacmd list-sink-inputs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With