How do I get pulseaudio to start automatically in Ubuntu 17.04 and 17.10 for Firefox?
Solution 1
This is a workaround that I'm treating as the answer until someone can identify to me that this is fixed in the upstream Ubuntu installation logic that handles desktop user configuration:
I have a script I run at startup using the Startup Applications shown in this answer: https://unix.stackexchange.com/a/32616/21372 , so in that script I added:
# Start pulseaudio because something got broken in Ubuntu or Firefox
# or PulseAudio or or
# or... (https://askubuntu.com/questions/962920/how-do-i-get-pulseaudio-to-start-automatically-in-ubuntu-17-04-for-firefox):
if ! pulseaudio --check
then
# But not via the old way:
#
# nohup pulseaudio > /dev/null 2>&1 &
#
# Use the proper way to enable this at login time per https://askubuntu.com/a/989674/340383
systemctl --user enable pulseaudio && systemctl --user start pulseaudio
fi
This checks to see if the pulseaudio process is started with the --check
option, and if it is not running, start it.
UPDATE #1:
I changed the workaround slightly to use the systemctl
commands as indicated in https://askubuntu.com/a/989674/340383
This is still a workaround as Ubuntu should have this enabled by default for desktop users.
I am reasoning that unfortunately I still have to have this workaround in place because the next time I upgrade or install from scratch, and run my new account the first time, if I don't have the above in my startup script, I will hence be baffled as to why sound stopped working.
A counter-argument: Since the systemctl calls will update the ~/.config files thusly (this is from the above systemctl...
command line):
Created symlink /home/drunkard/.config/systemd/user/default.target.wants/pulseaudio.service → /usr/lib/systemd/user/pulseaudio.service.
Created symlink /home/drunkard/.config/systemd/user/sockets.target.wants/pulseaudio.socket → /usr/lib/systemd/user/pulseaudio.socket.
then upon the next reinstallation of Ubuntu, then it should just be working properly. But that is only if I kept my ~/.config files which is not a good assumption: I keep all (except for files deep inside ~/.config!) of my "user configuration" files under a Git repository for this very reason of having to workaround usability problems that end up, just like this one, wasting a lot of my time in debugging it down to the root cause, which I don't want to do more than once.
Solution 2
A couple of days ago pulseaudio stopped loading for 18.04 - previously it worked just fine. after looking at all suggestions without permanent results, I just added the following line to the .profile
file:
pulseaudio --start
Related videos on Youtube
![bgoodr](https://i.stack.imgur.com/iqU0g.gif?s=256&g=1)
bgoodr
Updated on September 18, 2022Comments
-
bgoodr almost 2 years
I am trying to get Firefox 56.0 on Ubuntu 17.04 and 17.10 to play sound in videos in Facebook (not even sure it is specific to Facebook). I have isolated the problem down to pulseaudio not getting started when I play a video, or just not started at all. But if I execute pulseaudio from the command line, and then play the video from within Facebook, I get sound.
What is confusing me is trying to figure out what I should expect as to exactly when this pulseaudio UNIX process is supposed to be started.
- At boot time?
- At X11 startup time prior to user login?
- At user login (the "greeter" thing; GDM or whatever)?
- By Firefox when it executes code in some shared library that then demands that pulseaudio be started
https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/Running/ implies to me that it should be at user login time.
/etc/xdg/autostart is a directory that contains information about session services that graphical session managers should start automatically on user login. PulseAudio ships its own file there. pulseaudio.desktop tells the session manager to run start-pulseaudio-x11, which is a script that loads a few X11 related modules (and on KDE also module-device-manager, which is required by KDE's audio routing configuration tools). start-pulseaudio-x11 is usually the first thing that requires a running PulseAudio server, so usually the server gets started when the session manager runs start-pulseaudio-x11 in the beginning of the login session.
If autospawning is disabled, start-pulseaudio-x11 doesn't have effect, because start-pulseaudio-x11 doesn't start the server explicitly. It relies on autospawning when it loads the X11 modules. In this sense the script name is misleading. The start-pulseaudio-x11 script used to start the server explicitly in the past, which explains the script name.
Commands I've done recently to ensure I am starting from a good baseline, per instructions at http://support.system76.com/articles/audio/ (was done for different reasons, as the front audio connector in my machine was not working and doing the following fixed it):
rm -r ~/.config/pulse sudo apt install --reinstall alsa-base alsa-utils pulseaudio linux-sound-base libasound2
I am not at the moment thinking that the missing
~/.config/pulse
directory is the culprit, but is it?dmesg | grep pulse
shows nothing, so it is as if something is not even executing the right script at the right time.
What do I need to change to get this enabled? I don't want to manually invoke
pulseaudio
each time I run firefox (I can kludge something up script-wise, but I don't wanna).I conclude that autospawn is enabled since it is commented out (assuming commented out means the thing being commented out IS the program's default):
drunkard@norehab:~$ ps -ef --forest --cols=10000 | grep pulse drunkard 3448 2721 0 14:25 pts/0 00:00:00 | \_ grep pulse drunkard@norehab:~$ ls -ld ~/.config/pulse ls: cannot access '/home/drunkard/.config/pulse': No such file or directory drunkard@norehab:~$ ls -ld /etc/xdg/autostart/pulseaudio-kde.desktop ls: cannot access '/etc/xdg/autostart/pulseaudio-kde.desktop': No such file or directory drunkard@norehab:~$ ls -ld /etc/xdg/autostart/pulseaudio* -rw-r--r-- 1 root root 4836 Mar 29 2017 /etc/xdg/autostart/pulseaudio.desktop drunkard@norehab:~$ grep auto /etc/pulse/client.conf ; autospawn = yes ; auto-connect-localhost = no ; auto-connect-display = no drunkard@norehab:~$
UPDATE #1
I tried this:
cp -p /etc/pulse/client.conf ~/.config/pulse/client.conf
And rebooted and it is still not automatically starting.
UPDATE #2
The following proves to me that
/usr/bin/start-pulseaudio-x11
is NOT getting executed at all:I saved off
/usr/bin/start-pulseaudio-x11
:drunkard@norehab:~$ sudo cp -p /usr/bin/start-pulseaudio-x11 /usr/bin/start-pulseaudio-x11.orig
Then added a line at the end that simply writes out the curent timestamp to a log file in
/tmp/start-pulseaudio-x11.log
:drunkard@norehab:~$ sudo sh -c 'echo "date >> /tmp/start-pulseaudio-x11.log" >> /usr/bin/start-pulseaudio-x11' drunkard@norehab:~$ tail /usr/bin/start-pulseaudio-x11 if [ x"$KDE_FULL_SESSION" = x"true" ]; then /usr/bin/pactl load-module module-device-manager "do_routing=1" > /dev/null fi if [ x"$SESSION_MANAGER" != x ] ; then /usr/bin/pactl load-module module-x11-xsmp "display=$DISPLAY session_manager=$SESSION_MANAGER" > /dev/null fi fi date >> /tmp/start-pulseaudio-x11.log drunkard@norehab:~$
Then reboot and logged in and found that the
/tmp/start-pulseaudio-x11.log
was non-existent.So whatever is supposed to invoke
/usr/bin/start-pulseaudio-x11
before or after login is not doing so.UPDATE #3
This is still broken in Ubuntu 17.10. but the comment clued me in that my workaround can use
systemctl
instead of direct execution.But I say this is still broken because why is sound not enabled for all users that are using desktops? I mean, under no circumstances that I can think of would I ever NOT want to hear sound from videos played from any browsers. Whatever sound daemon (pulseaudio in this case but it doesn't matter) should be default to "enabled" for desktop users. Not so for server installations, but that is not the case here.
-
ravery over 6 yearspulse should be started by the time the desktop launches. I'm not sure if it is at log in or earlier
-
bgoodr over 6 yearsSure. That is what I concluded, but then if
/etc/xdg/autostart/pulseaudio.desktop
exists, then why isn't it being started? -
ravery over 6 yearsyou are missing the config files. (/home/drunkard/,config/pulse/) this may be the issue
-
bgoodr over 6 years@ravery Ok, I'll bite: How is the noobie user to know what to place there sans reading 100% of the pulseaudio manual?
-
bgoodr over 6 yearsSee UPDATE #1 where I tried to install some basic config and it did not automatically start up.
-
bgoodr over 6 yearsSee UPDATE #2 where I instrumented what I think is the script that should be executed at or before X11 login to verify that it is not getting invoked at all.
-
bgoodr over 6 yearsI gave up and did what I did not want to do which is to hack around something that should just be working out of the box, and answered my own question. :(
-
Redbob over 6 yearsAccording to this document,
~/.config/autostart/
files are more important than/etc/xdg/autostart/
ones. So I ask you if there is an empty or damagedpulseaudio.desktop
within there. -
bgoodr over 6 years@Redbob I checked, and there is no
pulseaudio.desktop
file in there at all. -
Redbob over 6 yearsIf you
copy /etc/xdg/autostart/pulseaudio.desktop ~/.config/autostart
folder, won't it works? -
tforgione over 6 yearsHave you seen this ? It's for ubuntu 17.10 but who knows...
-
bgoodr over 6 years@tforgione No I did not and thank you for the link. I have since provided Update #3 in the original description. Note my comments about this being still broken. I will hence update my workaround non-answer below at askubuntu.com/a/962926/340383 accordingly
-
bgoodr over 6 yearsaskubuntu.com/a/962926/340383 now updated with UPDATE #1
-
Adiraju over 3 yearsThank you so much for the suggestion, it fixed my problem :)
echo 'pulseaudio --start' >> ~/.profile