My setup

System 76 Kudu-Pro laptop with Ubuntu 16.04 LTS that I installed and keep regularly upgraded every few days. I am using Unity as my primary desktop with 12 users I frequently switch among to do specific tasks and for security isolation.

The problem

I start music playing then switch user and the music stops. This even happens if I ssh to localhost, unset the DISPLAY environment variable, become root, and play the music by a command (mplayer) from this session. I first encountered this problem on 14.04 LTS which was the first version I was using Unity and came pre-installed on the laptop. when switch user back to the same user that started playing the music, the music resumes. this also applies to audio played by the browser, such as Youtube videos.

My Question

How can I play music that keeps on playing (in a virtual background?) when I switch user? Also: Is PulseAudio involved in this?


If the solution needs root or sudo access, I can do that. If the solution needs some small-scale programming, I can do that in C and/or Python. I have been thinking that one possible workaround is to get a USB audio device and hope this 2nd audio device can be made to work.

  • I believe that is a pulseaudio feature rather than an issue. Imagine some user starts music and goes away... other users won't be able to stop that without root access for killing the player app. What player do you intend to use for starting playback? – Takkat Jul 24 '17 at 7:51
  • @Takkat it makes sense that it is a feature and would be great for a laptop shared among 2 or more people. but i am the only person using my laptop. right now my (inconvenient) workaround is using my old Asus netbook next to me to play the music. i am also looking for a portable music player that i can access with linux. i am hoping there is a simple way to bypass PulseAudio for this purpose. – Skaperen Jul 24 '17 at 8:19

Running PulseAudio system-wide

With running PulseAudio in system-wide mode any audio that an authorized user started will play in the background as long as this user is logged in.

Before you proceed please read the following on why usually running system-wide is not a good idea:

Nevertheless we can do that if we want to. Only authorized accounts will then be able to control volume or start another instance of sound output.

Preparing the system for running Pulseaudio in system-wide mode

Note down all changes you had made to be able to revert them in case you don't like the outcome (I tested all this in a virtual machine).

  1. Disable autospawn of pulseaudio for the user that will control audio

    echo autospawn = no > $HOME/.config/pulse/client.conf

    This prevents auto-spawning of pulseaudio for the given $HOME accounts. Settings here will override the system-wide settings in /etc/pulse which of course can be made alternatively.

  2. Stop a running instance of pulseaudio in user mode

    pulseaudio -k
  3. Prepare users and groups needed (in case they do not yet exist)

    sudo addgroup --system pulse
    sudo adduser --system --ingroup pulse --home /var/run/pulse pulse
    sudo addgroup --system pulse-access
    sudo adduser pulse audio
  4. Allow user(s) to access the system wide PulseAudio

    sudo adduser <username> pulse-access

    Only users added to pulse-access will be able to control volume of a playing audio.

Start pulseaudio in system-wide mode

sudo pulseaudio --system

Source and further reading: Running PulseAudio as System-Wide Daemon

  • looks good. i will try to set it up, tonight. i am curious, do you know where pulseaudio gets started in a default ubuntu 16.04 desktop system (so i can make it always run this way each time i boot up)? – Skaperen Jul 25 '17 at 3:02
  • i can switch user and the music keeps playing. one strange effect, the new user's audio level setting comes into effect when i switch. i can deal with that by setting the level on all the users. – Skaperen Jul 25 '17 at 4:16
  • i now have my laptop ubuntu set up to automatically start pulseaudio in system mode in a screen background session under root when i start the system up and automatically start my music in another screen background sesssion under one of my non-root working/development users. – Skaperen Jul 27 '17 at 0:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.