Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect that the sound is currently playing in Linux?

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?

like image 994
mhd Avatar asked Jul 01 '13 12:07

mhd


People also ask

How do I check my audio drivers Linux?

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.


2 Answers

Check if any /proc/asound/card*/pcm*/sub*/status file contains state: RUNNING.

like image 185
CL. Avatar answered Oct 04 '22 11:10

CL.


I use this:

pacmd list-sink-inputs
like image 22
glenn jackman Avatar answered Oct 04 '22 09:10

glenn jackman