I often have two KDE sessions running as two different users. When I switch between them (e.g. Ctrl+Alt+F8) music that is playing in one of the accounts is muted on the other account. The same happens when I switch to a virtual terminal (Ctrl+Alt+F1).
As far as I know this is on purpose and makes sense for multiple human users but is annoying in my setup.
How can I keep music hearable whenever I switch to another KDE session or a virtual terminal?
I am using KDE Neon 5 based on Ubuntu 16.04 LTS (Xenial Xerus) with KDE 5.36.0 and Pulseaudio 8.0.
Best Answer
Solution
Add all users that should be able play back to the pulse-access group
# adduser problemofficer pulse-access
Create /etc/systemd/system/pulseaudio.service with the following content:
Enable this new systemd service so that it is started on boot:
# systemctl enable pulseaudio
Be aware that this configuration is
Reboot
Cause
The reason why the sound turns of is that Pulseaudio is started on each login with this users privileges and the system¹ does not allow other users to listen on other users audio.
Solution Background
Pulseaudio
In order to solve this problem Pulseaudio must be started with root privileges so that it runs as a system wide daemon of which there is only for all users. Everyone will connect to this one instance and will be able to playback and listen to everything other users playback or record.
Pulseaudio will not actually run as root the whole time, but will drop those privileges and assume the user pulse.
From
man pulseaudio
Note that "user daemon" is not the same as "system deamon". The former is how Pulseaudio ran before, the latter is how it will run if the changes are applied.
In order to be able to connect to the Pulseaudio system service you need to be a member of the pulse-access group.
Again from
man pulseaudio
Systemd Service
As a quick work around it would be possible to simply kill all "user daemon" instances of Pulseaudio and then run
/usr/bin/pulseaudio --system=yes
. This would start Pulseaudio without it becoming a daemon and in a more insecure way but might be useful for a quick proof-of-concept check.To make this persistent and for the Pulseaudio daemon to start automatically on startup it needs to added as a systemd service. This is what the file /etc/systemd/system/pulseaudio.service is for.
Pulseaudio will not start a user daemon² when it already finds a system daemon, this is why this solution works.
Caveat
The official Pulseaudio documentation advices against using Pulseaudio as a system daemon. Some of the problems mentioned are:
(That means when you plug-in headphones the sound output does not automatically switch from speakers to headphones. The reverse is also true when you remove the headphones. Both have to be done manually.)
(Personally I haven't noticed any change in load though.)
And possibly other things that I do not understand and therefore did not felt were worthwhile including here.
Note regarding thecarpy's answer: None of the steps described in his answer were necessary for this solution.
Ressources
man pulseaudio
¹ If someone can explain this in detail, I would be very thankful.
² Assumption [citation required]