2021-04-09 13:37:54 -04:00
# OwnTone and Pulseaudio
2017-11-05 14:33:53 -05:00
2017-11-06 11:37:11 -05:00
You have the choice of runnning Pulseaudio either in system mode or user mode.
For headless servers, i.e. systems without desktop users, system mode is
recommended.
2017-11-05 14:33:53 -05:00
2017-11-06 11:37:11 -05:00
If there is a desktop user logged in most of the time, a setup with network
access via localhost only for daemons is a more appropriate solution, since the
normal user administration (with, e.g., `pulseaudio -k` ) works as advertised.
Also, the user specific configuration for pulseaudio is preserved across
sessions as expected.
2017-11-05 14:33:53 -05:00
2017-11-06 11:37:11 -05:00
- [System mode ](#system-mode-with-bluetooth-support )
- [User mode ](#user-mode-with-network-access )
2017-11-05 14:33:53 -05:00
2017-11-06 11:37:11 -05:00
## System Mode with Bluetooth support
2017-11-05 14:33:53 -05:00
2017-11-06 11:37:11 -05:00
Credit: [Rob Pope ](http://robpope.co.uk/blog/post/setting-up-forked-daapd-with-bluetooth )
2017-11-05 14:33:53 -05:00
2016-10-01 15:24:37 -04:00
This guide was written based on headless Debian Jessie platforms. Most of the
instructions will require that you are root.
2016-09-29 16:48:27 -04:00
2017-11-06 11:37:11 -05:00
### Step 1: Setting up Pulseaudio
2016-09-28 16:30:25 -04:00
2021-04-09 13:37:54 -04:00
If you see a "Connection refused" error when starting the server, then you
2016-09-29 16:48:27 -04:00
will probably need to setup Pulseaudio to run in system mode [1]. This means
that the Pulseaudio daemon will be started during boot and be available to all
users.
2016-09-28 16:30:25 -04:00
How to start Pulseaudio depends on your distribution, but in many cases you will
need to add a pulseaudio.service file to /etc/systemd/system with the following
content:
2016-09-28 16:58:51 -04:00
```
# systemd service file for Pulseaudio running in system mode
[Unit]
Description=Pulseaudio sound server
Before=sound.target
[Service]
ExecStart=/usr/bin/pulseaudio --system --disallow-exit
[Install]
WantedBy=multi-user.target
```
2016-09-28 16:30:25 -04:00
2016-09-29 16:48:27 -04:00
If you want Bluetooth support, you must also configure Pulseaudio to load the
2017-11-05 14:33:53 -05:00
Bluetooth module. First install it (Debian:
2016-10-01 15:24:37 -04:00
`apt install pulseaudio-module-bluetooth` ) and then add the following to
/etc/pulse/system.pa:
2016-09-29 16:48:27 -04:00
```
2017-11-05 14:33:53 -05:00
#### Enable Bluetooth
2016-09-29 16:48:27 -04:00
.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
.endif
```
2016-10-01 15:24:37 -04:00
Now you need to make sure that Pulseaudio can communicate with the Bluetooth
daemon through D-Bus. On Raspbian this is already enabled, and you can skip this
step. Otherwise do one of the following:
1. Add the pulse user to the bluetooth group: `adduser pulse bluetooth`
2. Edit /etc/dbus-1/system.d/bluetooth.conf and change the policy for
2016-10-01 17:05:25 -04:00
\<policy context="default"\> to "allow"
2016-10-01 15:24:37 -04:00
Phew, almost done with Pulseaudio! Now you should:
1. enable system mode on boot with `systemctl enable pulseaudio`
2. reboot (or at least restart dbus and pulseaudio)
3. check that the Bluetooth module is loaded with `pactl list modules short`
2016-09-28 16:30:25 -04:00
2021-04-09 13:37:54 -04:00
### Step 2: Setting up the server
2016-09-28 16:30:25 -04:00
2021-04-09 13:37:54 -04:00
Add the user the server is running as (typically "owntone") to the
2016-09-29 16:48:27 -04:00
"pulse-access" group:
2016-09-28 16:30:25 -04:00
2016-09-28 16:58:51 -04:00
```
adduser daapd pulse-access
```
2016-09-28 16:30:25 -04:00
2021-04-09 13:37:54 -04:00
Now (re)start the server.
2016-09-29 16:48:27 -04:00
2017-11-05 14:33:53 -05:00
### Step 3: Adding a Bluetooth device
2016-09-29 16:48:27 -04:00
To connect with the device, run `bluetoothctl` and then:
```
power on
agent on
scan on
**Note MAC address of BT Speaker**
pair [MAC address]
**Type Pin if prompted**
trust [MAC address]
connect [MAC address]
```
2016-09-28 16:30:25 -04:00
2021-04-09 13:37:54 -04:00
Now the speaker should appear. You can also verify that Pulseaudio has detected
the speaker with `pactl list sinks short` .
2016-09-28 16:30:25 -04:00
2017-11-06 11:37:11 -05:00
## User Mode with Network Access
Credit: wolfmanx and [this blog ](http://billauer.co.il/blog/2014/01/pa-multiple-users/ )
### Step 1: Copy system pulseaudio configuration to the users home directory
```
mkdir -p ~/.pulse
cp /etc/pulse/default.pa ~/.pulse/
```
### Step 2: Enable TCP access from localhost only
Edit the file `~/.pulse/default.pa` , adding the following line at the end:
```
load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1
```
### Step 3: Restart the pulseaudio deamon
```
pulseaudio -k
# OR
pulseaudio -D
```
### Step 4: Adjust configuration file
2021-04-09 13:37:54 -04:00
In the `audio` section of `/etc/owntone.conf` , set `server` to `localhost` :
2017-11-06 11:37:11 -05:00
```
server = "localhost"
```
2016-09-29 16:48:27 -04:00
---
2016-09-28 16:30:25 -04:00
2016-09-29 16:48:27 -04:00
[1] Note that Pulseaudio will warn against system mode. However, in this use
case it is actually the solution recommended by the [Pulseaudio folks themselves ](https://lists.freedesktop.org/archives/pulseaudio-discuss/2016-August/026823.html ).