Skip to content

Commit

Permalink
Merge pull request #67 from Aerion/fix-buffer-output-delay
Browse files Browse the repository at this point in the history
Fix buffering output delay
  • Loading branch information
marioortizmanero authored Jul 2, 2022
2 parents d3df2cb + 26388ed commit 166a778
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pulseaudio-control.bash
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,16 @@ function listen() {
# This is faster than having the script on an interval.
pactl subscribe 2>/dev/null | grep --line-buffered -e "on card" -e "on sink" -e "on server" | {
while read -r; do
# Output the new state
output

# Read all stdin to flush unwanted pending events, i.e. if there are
# 15 events at the same time (100ms window), output is called once.
# 15 events at the same time (100ms window), output is only called
# twice.
read -r -d '' -t 0.1 -n 10000

# After the 100ms waiting time, output again the state, as it may
# have changed if the user did an action during the 100ms window.
output
done
}
Expand Down

0 comments on commit 166a778

Please sign in to comment.