I need to switch the pulseaudio server of a currently playing audio stream.
Pulseaudio server is set up with IP 192.168.1.105
$>cat /etc/pulse/default.pa
...
load-module module-esound-protocol-tcp auth-anonymous=1
load-module module-native-protocol-tcp auth-anonymous=1
load-module module-zeroconf-publish
...
On the source side VLC media player is playing a song.
I created a new tunnel sink with pulseaudio on source side.
pacmd load-module module-tunnel-sink server=192.168.1.105
pacmd set-default-sink 1
But while playing audio the server couldn't be changed immediately. Only after stopping the player and replay, it's ok.
From "gnome-volume-control" or "gnome-control-center sound" switching of output devices is applied immediately.
How can I apply switching the output sink immediately from command line during playback of a sound file?
Best Answer
PulseAudio
pacmd
is not capable of switching the default sinks while there is an actively playing stream to the sink input. However there is a way to still achieve this.Changing default sink from command line
First we need to determine the index number of the sinks we want to switch. This can be done by calling:
Depending on our system this will give you a more or less lengthy list of sinks and properties that are at present accessible:
The
index
or thename
given here is what we need for adressing the sink by command line. The present default sink is marked with an asterix (here0
).To be able to switch the default sinks from command line we may need to disable stream target device restore by editing the corresponing line in
/etc/pulse/default.pa
to:To change the default output sink to sink
1
we then runSucess can be visualized by opening the Sound Settings menu.
Moving a stream to another sink
Changing the default sink while we have an active input stream playing to a given sink has no effect. This should rather be done by moving this input to another sink.
will tell us the index of the input stream
We now know that we want to move the input stream
5
to sink1
by callingor back to sink
0
if we like. This will be done immediately without the need of stopping playback.Changing default sink while playing
Of course we can combine those two commands to immediately switch default sinks during playback e.g. with
A drawback of this method is that the input stream index changes every time we stop and restart the music player. So we always have to find out the current stream index before we can switch using the commmand line.