How to config sound output by bluetooth headset in manjaro i3

These days, I change my desktop environment to i3. In manjaro gnome, I can config sound output by bluetooth headset and gnome can auto change the sound source. But i3 can't auto change the sound source. I try config it by right click volume icon and It does not work. Is there anyone know hot to solve it.

You need pulseaudio and pulseaudio-bluetooth installed. Probably you have to add
load-module module-switch-on-connect
to /etc/pulse/default.pa


in i3 config maybe something like this:

# Pulse Audio controls 
bindsym XF86AudioRaiseVolume exec pactl set-sink-volume 0 +5% #increase sound volume 
bindsym XF86AudioLowerVolume exec pactl set-sink-volume 0 -5% #decrease sound volume 
bindsym XF86AudioMute exec pactl set-sink-mute 0 toggle # mute sound

There is a script that maybe is useful for you:

#!/bin/bash
EXIST="$(pacmd list-sinks | grep name: | grep <BLUETOOH SINK>)"
if [ -z "$EXIST" ]; then
    pactl set-default-sink '<INTERNAL SINK>'
else
    pactl set-default-sink '<BLUETOOH SINK>'
fi

load it manually or trough custom keyboards shortcut ...

I have installed them, there is another problem. It prompt establishing connection to pulseaudio please wait... when I run pavucontrol.
here is pulseaudio -vvv output
I: [pulseaudio] main.c: setrlimit(RLIMIT_NICE, (31, 31)) failed: 不允许的操作
I: [pulseaudio] main.c: setrlimit(RLIMIT_RTPRIO, (9, 9)) failed: 不允许的操作
D: [pulseaudio] core-rtclock.c: Timer slack is set to 50 us.
D: [pulseaudio] core-util.c: RealtimeKit worked.
I: [pulseaudio] core-util.c: Successfully gained nice level -11.
I: [pulseaudio] main.c: This is PulseAudio 13.0
D: [pulseaudio] main.c: Compilation host: x86_64
D: [pulseaudio] main.c: Compilation CFLAGS: Not yet supported on meson
D: [pulseaudio] main.c: Running on host: Linux x86_64 5.6.12-1-MANJARO #1 SMP PREEMPT Sun May 10 14:36:43 UTC 2020
D: [pulseaudio] main.c: Found 8 CPUs.
I: [pulseaudio] main.c: Page size is 4096 bytes
D: [pulseaudio] main.c: Compiled with Valgrind support: no
D: [pulseaudio] main.c: Running in valgrind mode: no
D: [pulseaudio] main.c: Running in VM: no
D: [pulseaudio] main.c: Running from build tree: no
D: [pulseaudio] main.c: Optimized build: yes
D: [pulseaudio] main.c: All asserts enabled.
I: [pulseaudio] main.c: Machine ID is 072393f907b8409ab35a7f491905ce48.
I: [pulseaudio] main.c: Session ID is 2.
I: [pulseaudio] main.c: Using runtime directory /run/user/1000/pulse.
I: [pulseaudio] main.c: Using state directory /home/jonty/.config/pulse.
I: [pulseaudio] main.c: Using modules directory /usr/lib/pulse-13.0/modules.
I: [pulseaudio] main.c: Running in system mode: no
E: [pulseaudio] pid.c: Daemon already running.
E: [pulseaudio] main.c: pa_pid_file_create() 失败。

Did you reboot the system ?

Yes,I have reboot system many times.

When I run pulseaudio on terminal
E: [pulseaudio] pid.c: Daemon already running.
E: [pulseaudio] main.c: pa_pid_file_create() failure

Did I forget to configure something?

Don't confuse pulseaudio with pavucontrol
Also, see what sink is using when connected.
https://wiki.archlinux.org/index.php/Bluetooth_headset

Thank you for your help

Forum kindly sponsored by