Bluetooth A2DP pulseaudio source to play sound from phone to linux with bluez 5.45

8,651

Well, I spent hours working on this and for some reason was unable to connect to my phone. However, I then tried on a different computer, and simply typing connect xx:xx:xx:xx:xx:xx in the bluetoothctl shell was enough to connect and get audio working. Then I went back to the first computer, ran remove xx:xx:xx:xx:xx:xx and re-paired, and then it worked.

The one thing I did differently was to be playing music while pairing and connecting in the cases that worked, while in the first case I tried connecting before sending audio.

So basically to summarize for other people who are trying to get bluetooth working on arch, these are the steps:

pacman --needed -S pulseaudio-bluetooth bluez-utils bluez-tools rfkill
systemctl enable bluetooth
systemctl start bluetooth
rfkill unblock bluetooth
gpasswd -a `logname` lp

Then as yourself run pulseaudio -k, log out, and log in again to get into the lp group (which provides bluetooth access).

Now play music from your phone's built-in speaker and place your phone in pairing mode.

Finally, once again as root run bluetoothctl, and from within the utility run the following commands:

power on
scan on
pair xx:xx:xx:xx:xx:xx
[confirm pin]
scan off
connect xx:xx:xx:xx:xx:xx
trust xx:xx:xx:xx:xx:xx

At this point if things are working the phone will stop playing through its speaker, and you will see a new input under the pavucontrol application.

Note, the trust command is necessary if you want your phone to connect automatically when it is in range, without you needing to run a copy of bt-agent to authorize the phone's access to your sound. Otherwise, you will need to initiate all connections from your computer, either with the connect command in bluetoothctl, or with a command like this:

dbus-send --system --type=method_call --dest=org.bluez \
    /org/bluez/hci0/dev_xx_xx_xx_xx_xx_xx org.bluez.Device1.Connect
Share:
8,651

Related videos on Youtube

user3188445
Author by

user3188445

I'm in the computer security field and have been using C and Unix since before 1990. I have extensive development experience in C++ and Haskell. For C++, I hate boost, and so do everything either directly on the standard library or using my own templates. I write a lot of bash and emacs lisp, too, and at a previous stage of my career turned out a lot of perl (though I haven't used perl in years). I've dabbled in TeX and written some LaTeX classes used by others, but am far from an expert. I prefer the command line to all other interfaces, especially web browsers. I love git as much as I hate github. I try to write and use free software whenever possible, and have pretty much succeeded on the writing front but am sometimes forced into using proprietary systems (like the baseband on my phone).

Updated on September 18, 2022

Comments

  • user3188445
    user3188445 over 1 year

    I'm trying to make sound from my phone show up as a pulseaudio input so that I can play music through my computer's speakers using bluetooth A2DP. I'm using arch linux with bluez 5.45.

    There are tons of guides about this on the web, but they all seem out of date. In particular, with bluez 5.45 (and bluez-utils 5.45 and bluez-tools 0.2) there is no file /etc/bluetooth/audio.conf anymore. hcitool and sdptool do not exist any more. There is no longer an org.bluez.AudioSource interface I can call on hci devices over dbus. Some web pages suggest things should "just work" now, but I certainly don't see any sources or sinks after pairing my phone (a Pixel) with my computer.

    What does work: I am able to pair my phone from bluetoothctl and ping it with l2ping. I placed my user in the lp group and edited /etc/dbus-1/system.d/bluetooth.conf so I have all possible bluetooth permissions. pacmd list-modules shows that I have loaded module-bluetooth-policy, module-bluetooth-discover, and module-bluez5-discover. On my phone's bluetooth menu, my computer shows up as used for "Media audio" (don't know if that's right or not).

    However, pacmd list-sources doesn't list anything about bluetooth, and there's not a hint of bluetooth anything under pavucontrol.

  • isaacsloan
    isaacsloan over 6 years
    I'm able to get this to connect and it shows up in pavucontrol. My audio also stops playing on my phone as you mentioned. I can't figure out what to do from their though. I've tried choosing combinations of input/output between speakers and phone input and all phone input and output. I can't get any sound though. Do I need to do something to route from input to output? Were there any other steps for you?