47

First, the problem: I'm using a Cowon MP3 player as my main music player with basic earplugs.

It offers A2DP & I'd like to have my netbook (running UNE 10.04) act as receiver.

Some resources on the web about a2dp, but most are out of date:

0

6 Answers 6

56
+500

To use your Ubuntu machine as an a2dp Bluetooth device, you must first configure it to register as an "a2dp sink" endpoint.

The bluez package in Ubuntu (10.04 and above) includes a utility called sdptool that can be used to check whether a Bluetooth device is configured as an a2dp sink or not. Here is the output from sdptool run against my Bluetooth headset (the address is taking from the "Bluetooth settings" dialog in the gnome-control-center):

$ sdptool search --bdaddr 00:18:16:3A:3B:D4 a2snk
Searching for a2snk on 00:18:16:3A:3B:D4 ...
Service RecHandle: 0x10002
Service Class ID List:
  "Audio Sink" (0x110b)
Protocol Descriptor List:
  "L2CAP" (0x0100)
    PSM: 25
  "AVDTP" (0x0019)
    uint16: 0x102
Profile Descriptor List:
  "Advanced Audio" (0x110d)
    Version: 0x0102

$

and here is the output when run against my local Ubuntu machine:

$ sdptool search --bdaddr local a2snk
Searching for a2snk on FF:FF:FF:00:00:00 ...
$

This shows that the Ubuntu machine is not advertising itself as an a2dp sink. It is advertising itself as an a2dp source however:

$ sdptool search --bdaddr local a2src
Searching for a2src on FF:FF:FF:00:00:00 ...
Service Name: Audio Source
Service RecHandle: 0x10003
Service Class ID List:
  "Audio Source" (0x110a)
Protocol Descriptor List:
  "L2CAP" (0x0100)
    PSM: 25
  "AVDTP" (0x0019)
    uint16: 0x102
Profile Descriptor List:
  "Advanced Audio" (0x110d)
    Version: 0x0102

This enables the Ubuntu machine to pair correctly with the headset as an audio source, but it does not enable using the Ubuntu machine as an output (sink) for Bluetooth audio.

If you edit /etc/bluetooth/audio.conf, you can enable a2dp sink support by adding this line underneath the [General] section:

  Enable=Source

This is both counterintuitively named--since what we're adding here is Bluetooth sink support, not source support--and in contradiction with the comment in this file that claims all implemented services are enabled by default. :(

After making this change, you will need to restart bluetoothd by running sudo service bluetooth restart.

If you have previously paired your Android device and Ubuntu computer while trying to get this work, you will need to delete the pairing on both sides and re-pair them in order to get Android to recognize Ubuntu as an available audio device.

Once you've done this, the Android device should show up as an input device under PulseAudio. If PulseAudio does not detect the new Bluetooth audio source, you may need to install and load the Bluetooth module, from the command line:

 sudo apt-get install pulseaudio-module-bluetooth
 pactl load-module module-bluetooth-discover

Then you need to tell PulseAudio to route this audio input to your output/sink (such as your speakers, or a Bluetooth headset) using a loopback connection (a straight line from a source to a sink).

Later versions of PulseAudio may have module-bluetooth-policy included and it may already have set up a loopback device for you, but this does not seem to be the most common case.

A semi-automatic way to set up the loopback connection - if you also have the pavucontrol GUI program installed - is to simply load the loopback module and configure it using pavucontrol, since PulseAudio will remember the settings. Loading the module is done from the command using pactl:

 pactl load-module module-loopback

Don't fear if you don't hear anything yet, or if you get strange feedback effects, we need to tell the newly created device which source to get input from and which sink to send the output to first.

Open pavucontrol and open its Configuration tab. Make sure your Bluetooth device shows up here (after pairing with it using blueman-manager or another Bluetooth tool) and the profile is set to A2DP. Switch to the Input devices tab and make sure your device shows up here as well and is not muted. Now switch to the Recording tab and make the newly created loopback connection use your device as a source with the select box next to the mute button. Switch to the Playback tab to select the sink the loopback connection should use in the same way. If the loopback device does not show in the tabs, make sure all streams are displayed using the selectbox at the bottom of each tab.

You should now hear the audio from your device, if it's playing, in your speakers, or whichever output sink you selected. When your device is disconnected the loopback device will fallback to an available sink and source, which may not be desirable, so make sure you mute the loopback device until you need it. The loopback connection will restore the same sink/source the next time the same Bluetooth device is connected thanks to the module-*-restore modules.

If that doesn't work, or you don't have pavucontrol installed, you may instead set up the loopback using the following method:

 pactl load-module module-loopback source_dont_move=yes source=$BTSOURCE sink=$SINK

(Replace $BTSOURCE with the source name for your Bluetooth device as seen by PulseAudio, e.g. bluez_source.14_DA_E9_2A_D7_57; and replace $SINK with the name of the PulseAudio output you want to send the audio stream to, e.g: alsa_output.pci-0000_00_1b.0.analog-stereo. You may leave out the sink argument entirely and have it fallback to an active sink, and change it later via pavucontrol.)

  • You can find $SINK with pactl list sinks, it's shown after Name:
  • Similarly you can see the $BTSOURCE with pactl list sources
  • The source_dont_move argument prevents the loopback connection from falling back to another audio source when the Bluetooth device is disconnected. It is instead removed and you'll have to set it up again next time.

Here's what an example one would look like (Remember to replace the : with _ in the Bluetooth address!):

pactl load-module module-loopback source_dont_move=yes source=bluez_source.14_DA_E9_2A_D7_57 sink=alsa_output.pci-0000_00_14.2.analog-stereo

If loading the fallback module fails, try removing the source_dont_move=yes argument, it was made available first in version 1.0. Then be careful however to remove this loopback connection before you drop this audio, or if for instance your laptop microphone is unmuted, you may get some very bad feedback. To drop this loopback connection manually when you're done, run:

pactl unload-module $(pactl list short modules | grep "loopback.*$BTSOURCE" | cut -f1)

Again, replace $BTSOURCE with the name for the PulseAudio source that refers to your Bluetooth device. You may also unload the module using the id returned by the load-module command:

$ pactl load-module module-loopback source_dont_move=yes source=bluez_source.14_DA_E9_2A_D7_57 sink=alsa_output.pci-0000_00_14.2.analog-stereo
15
$ pactl unload-module 15

References:

  • Blog post outlining some of the details on how this is being fixed in Ubuntu.
11
  • can we changes the channel map for particular device sink Apr 28, 2014 at 8:17
  • hi theree and thank you for the detailed guide. The command pactl load-module module-bluethooth-discover fails in ubuntu studio 14.04. So I do not see any bluez sources in pulseaudio, even though my phone correctly sees the pc as an audio sink. Any ideas?
    – nass
    Dec 14, 2014 at 9:15
  • if pactl list sources short doesn't show the bluez source for you, I've found two possible solutions: call gdbus call --system --dest org.bluez --object-path /org/bluez/XXX/hci0/dev_XX_XX_XX_XX_XX_XX --method org.bluez.AudioSource.Connect where (the path includes the device BD address and the adapter path wich you can get with gdbus call --system --dest org.bluez --object-path / --method org.bluez.Manager.DefaultAdapter). Or use d-feet as explained here. Otherwise connect on phone side, and start playing something.
    – Treviño
    Mar 25, 2016 at 16:52
  • I still don't see any source from bluez showing up. Linux Mint 17.3 "Rosa" here.
    – donquixote
    Jan 10, 2017 at 3:12
  • 1
    Wow! with minimal changes(/etc/bluetooth/main.conf instead of audio.conf) this works on Rasbian. Thank you!(no loopback configuration is needed in that OS)
    – jamie
    Dec 28, 2017 at 17:04
14

I use blueman, installed from Ubuntu software center. Right-clicking on the blueman icon*-> "local services" -> audio-> Check "advanced audio reception" is tipped. Btw I use it to listen in my Ubuntu 11.10 laptop what I play on my android phone.

*The blueman icon is showed in bottom-right corner in gnome shell + ubuntu 11.10, that is my case. I hope this is useful in some way for you.

4
  • The blueman configuration interface for audio only sets the Enable=Source value in /etc/bluetooth/audio.conf, so I don't see how this would enable android to use a computer as an audio output.
    – slangasek
    Mar 2, 2012 at 23:15
  • ok, so if I set that in audio.conf and then unpair from both sides of the connection, that seems to be enough to let Android see the computer as an audio sink after all...
    – slangasek
    Mar 3, 2012 at 0:07
  • I tried that and couldn't get it to recognize it as the audio sink. :-/ Mar 4, 2012 at 19:14
  • blueman worked for me in 12.04 with zero issues other than the fact I ended up with two bluetooth icons in my indicator applet.
    – Dave
    Apr 24, 2012 at 19:16
7

It's really simple now in Ubuntu 12.04

Connect your bluetooth device

Search for your bluetooth device and take note of it's source number:

pactl list sources 

Make a loopback for the bluetooth device:

pactl load-module module-loopback source=$SOURCE_NUMBER  

Where $SOURCE_NUMBER is the number you previously took note of.

For example, I entered the following to get audio playback to work:

$ pactl load-module module-loopback source=3  

That's it! I found the solution in the top answer to be a bit complicated, so I simplified it this way (much less typing and copy/pasting). Though my solution will probably break if you remove any audio devices listed before the bluetooth device by pactl list sources.

Also, don't forget to remove the loopback module before disconnecting the bluetooth device:

Take note of the module number of the loopback device you created:

pactl list short modules

Remove the loopback device:

pactl unload-module $MODULE_NUMBER

The previous answers were written prior to 12.04's release, so I'm sure there were some changes. For example, I didn't have to manually enable using bluetooth devices as an audio source (it was enabled by default). However, I do sometimes have to toggle the "Media Audio" profile in my bluetooth settings on my phone (Samsung Captivate running CyanogenMod 9.1.0).

There's probably a way to leverage dbus-monitor by using a shell script to watch for bluetooth A2DP device connections and automatically load a loopback module for it, but that's a bit over my head.

Hopefully we won't need to do this manually any more in Ubuntu 12.10.

1
  • After loading module-loopback for particular sinks, can we change the channel map of module-loopback of Particular device to left or right Apr 28, 2014 at 8:16
4

For 13.04, pair your source device with the ubuntu laptop and it just works! Very cool to find that it was that easy now.

4

In Ubuntu 16.04 this works out-of-the-box.

2
  • Same, though the following (unreported) bug was stopping it, caught in the system journal: askubuntu.com/questions/689281/… Dec 10, 2017 at 8:12
  • Working in Ubuntu 22.04 as well. Paired my Lenovo Thinkpad T410 with my iPhone 6s and was able to start playing from the phone to the Thinkpad speakers immediately
    – alter_igel
    Jan 7 at 18:53
0

Even easier solution than the answer.

You can simply go

sudo apt-get install pulseaudio*

Then reboot. After reboot, connect to your Bluetooth and simply play the music on your phone. Everything will be transmitted to your computer and play out on the computer's speakers.

And yes! you're welcome.

5
  • apt-get uses regular expressions, not wildcards. So you have no idea what will be installed using pulseaudio* (hint: it's not just packages that begin with pulseaudi). And PulseAudio is already part of the default Ubuntu installation.
    – muru
    Dec 24, 2014 at 8:18
  • Yes! But this will work for all the lazy people who wants get things working instantly. Dec 24, 2014 at 10:03
  • @muru apt-get install accepts both regular expressions and globs, word.* and word*, though to avoid wildcard matching on the left you would be advised to use the regex ^word.* or (as said before) you may be surprised. Apr 21, 2020 at 12:46
  • @Orwellophile I know - and they changed it yet again for the apt command with V2.0
    – muru
    Apr 21, 2020 at 13:23
  • Just saying, installing every pulseaudio package out there is probably not the best idea. That would be akin to going to the store and purchasing every brand of cereal because you know you needed one of them but you can't remember which. May 3, 2020 at 5:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .