I'd like to only allow audio from a certain application. That is, I'd like to have audio turned off by default for new programs.
I'm aware that in PulseAudio one can mute programs, but the problem is that (for me) new programs always begin unmuted.
I'd like to only allow audio from a certain application. That is, I'd like to have audio turned off by default for new programs.
I'm aware that in PulseAudio one can mute programs, but the problem is that (for me) new programs always begin unmuted.
It's a shame that this option is not available... by the way, before starting your application, you can run this command:
for i in $(pactl list sink-inputs short | awk '{print $1}'); do
pactl set-sink-input-mute $i 1
done
It simply mutes all the active streams. However, new streams will still open unmuted. For this, you can add another loop to detect new streams and mute them as soon they start:
old_list=$(pactl list sink-inputs short)
while true; do
new_list=$(pactl list sink-inputs short)
if [[ "$old_list" != "$new_list" ]]; then
for i in $(pactl list sink-inputs short | awk '{print $1}'); do
pactl set-sink-input-mute $i 1
done
fi
done
The problem now is that it mutes even our application. So imagine naming the script like pa_solo_mode and use it like pa_solo_mode mycommand -with --any --option, e.g.
pa_solo_mode vlc -v
We now detect the process name and mute it only if the command is different.
function get_stream_pid_list {
pactl list sink-inputs | awk '
/application.process.id/ {
gsub("\"", "", $3)
print $3
}'
}
function get_stream_index_from_pid {
pid=$1
pactl list sink-inputs | awk '
/^Sink Input #[0-9]+$/ {
sub("#", "", $3)
x=$3
}
/application.process.id = "'$pid'"/ {
print x
}'
}
function daemon_mute_except {
except_pid=$1
echo "Muting all streams except $except_pid!"
while true; do
for pid in $(get_stream_pid_list); do
if [[ "$except_pid" != "$pid" ]]; then
index=$(get_stream_index_from_pid $pid)
pactl set-sink-input-mute $index 1
fi
done
sleep 0.25
done
}
# run our command and take its PID
$@ &
except_pid=$!
# start the daemon: continuously mute streams
daemon_mute_except $except_pid