After extensive testing and research, I have put together a complete work-around for playing high-quality audio through Bluetooth headphones using the Blueman Bluetooth application. I haven’t bothered testing this with other Bluetooth applications. If memory serves me, the alternative Bluetooth apps lack the ability to choose audio profiles – but I might be wrong. Going forward, just understand that this was done exclusively with Blueman.
Default Ubuntu Bluetooth settings work, but don’t work
By default, Ubuntu’s (and other distros’) Bluetooth settings provide working connections to most Bluetooth speakers and smartphones. Heck, using a cheap Bluetooth dongle on your computer, you can share your smart phone’s 4G Internet connection. Works incredibly well. And the same can be said when connecting to your Bluetooth speaker. Using the A2DP (Advanced Audio Distribution Profile) Bluetooth profile setting, today’s modern Bluetooth speakers work well because they only offer one profile – A2DP.
This leads us back to Bluetooth headphones. While there are exceptions, many of these headphones are actually headsets. This means they serve as a means of speaking to others over the phone or VoIP. Complete with a microphone, these headsets are considered to be HSP/HFP (Headset Profile) devices first, A2DP (high quality audio) second.
So here’s the meat of the problem with these headsets acting as headphones – Ubuntu’s default Bluetooth settings don’t like to cooperate with A2DP settings. Just as frustrating, the microphone portion of HSP doesn’t work due to a known bug.
– Bluetooth speakers using A2DP only work fine.
– Bluetooth headsets using HSP/A2DP do not. An exception to this might be headsets without HSP profile functionality.
To address this problem, we’re going to be editing some specific files so that we can get Bluetooth headsets to work correctly and provide us with A2DP functionality. This will allow us to enjoy high-quality audio for watching videos, listening to podcasts or simply enjoying our favorite music. Sadly, at this time I haven’t had any luck with getting HSP profiles to allow for microphone compatibility. This may be fixed sometime in the future.
Editing the right conf files
To make things work correctly, we’re going to edit the following.
/etc/Bluetooth/input.conf /usr/bin/start-pulseaudio-x11 /etc/Bluetooth/main.conf /etc/pulse/default.pa
Now, I highly recommend backing up each of these files before editing them.
sudo cp /etc/Bluetooth/input.conf /etc/Bluetooth/input.bak
sudo cp /usr/bin/start-pulseaudio-x11 /usr/bin/start-pulseaudio-x11.bak
sudo cp /etc/Bluetooth/main.conf /etc/Bluetooth/main.bak
sudo cp /etc/pulse/default.pa /etc/pulse/default.bak
By backing these files up, you’re able to restore them instantly should you find this doesn’t work with your headset in question. That said, if you follow my instructions, happen to be using bluez 5.37-0ubuntu5, pulseaudio 1:8.0-0ubuntu3.2 running on Ubuntu 16.04, you should have no problem getting this to work.
Important! Be aware that when I updated Ubuntu 16.04 to use a newer version of pulseaudio, I found that the ability to switch audio profiles wasn’t cooperating. I’m still testing the newer version of pulseaudio to see if any additional changes need to be made. Therefore, on my daily PC, I am only running with security updates and various PPAs – I’m not updating recommended or unsupported updates. This will change once I have a chance to better vet the newer pulseaudio package.
First, we have /etc/Bluetooth/input.conf to edit. With each file, my recommendation is to erase the contents of the original and replace it with my edited version of each file.
Erase the original contents of your /etc/Bluetooth/input.conf, then copy the above pastebin and make it your new /etc/Bluetooth/input.conf – the active part here is IdleTimeout=0, which should help prevent your Bluetooth from timing out.
Next we need to edit the /usr/bin/start-pulseaudio-x11 file:
The part of the file that matters here is below:
if [ x"$SESSION_MANAGER" != x ] ; then /usr/bin/pactl load-module module-x11-xsmp "display=$DISPLAY session_manager=$SESSION_MANAGER" > /dev/null fi
Now we begin editing the Bluetooth configuration itself, in /etc/Bluetooth/main.conf:
I won’t bother touching on all the parts of this file that allow stuff to work, but suffice it to say we’re setting this up with a minimal configuration.
Then finally, we have our system wide pulseaudio settings in /etc/pulse/default.pa:
In this file, you can find the changes by looking for Matt in the code. I added it for the sections that I tweaked for this file. For this file, I made changes to “load-module module-udev-detect tsched=0” and “load-module module-suspend-on-idle timeout=30.” Once again, this is informational only. You should be copying and pasting the entire configuration for each file after removing the original contents.
And that’s it! Assuming you backed up the original files, emptied the original file(s) contents, and pasted in my tweaked versions – you’re all ready to reboot your PC.
Blueman is the way to Bluetooth
With the computer rebooted, plug in your Linux compatible Bluetooth dongle. If your have Bluetooth installed on a laptop, just keep reading.
sudo apt install blueman
Now run Blueman, and then “Turn Bluetooth On” from the applet itself. Again from the applet, you will want to toggle down to Devices. First, put your headset into discoverable mode and then click Search on Blueman. Once Blueman detects the device, right click on the representative entry in Blueman, click Pair and then Trust.
Once the headset connects (it might take a moment), right click on the entry again and change the profile to Off. Turn off the headset. Now turn the headset on again, and then right click on entry and this time select the A2DP profile. From this moment on, you’re ready to listen to high quality audio through your Bluetooth headset.
So what about when you’re done with the headset? Well, you will need to stop the audio (music, etc) you’re listening to. Then go back to Blueman, right click on the entry and change the profile back to off. From here, you’re free to turn off and charge your headset.
The best part is that when you connect, your default sound device becomes the Bluetooth headset – automatically! And yes kids, this will work on other HSP/A2DP headsets as well.
Using Bluetooth headset on a daily basis:
Once set up, here are the usage instructions
– Turn on headset, switch entry profile to A2DP – enjoy.
When finished listening to headset…
– switch Bluetooth entry profile to Off – turn off headset.
This last part is literally all there is to it now that we did the heavy lifting with the initial setup.
Equipment used for Bluetooth Audio
– Levn M32-black Hi-fi V+4.1 Stereo Bluetooth Headset
– Plugable USB Bluetooth 4.0 Low Energy Micro Adapter
I also tested this using another HSp/A2DP headset that was earbud in nature and tried this on a MBP running Ubuntu MATE, with built in Bluetooth. This also worked!
Troubleshooting Bluetooth Audio
Ideally Bluetooth audio should play perfectly. But that’s not the nature of Bluetooth technology being piped through your desktop computer. Sometimes lag can get the better of the situation.
Problem: Bluetooth pairs and connects, but you can’t change profile.
– Erase your changed config files (you backed up the originals), try again following the above guide.
– Verify you’re using bluez 5.37-0ubuntu5, pulseaudio 1:8.0-0ubuntu3.2 on Ubuntu 16.04 LTS. I still need to test the newer releases of both packages before signing off on them.
Problem: Bluetooth works, but then it starts skipping and disconnects.
– Use a USB extension cable if you’re using a Bluetooth dongle on a desktop PC.
– Position Bluetooth dongle closer to where you use your headset.
– Sometimes bringing up dialog boxes or other PC activity can in rare cases make things skip.
– Perhaps most importantly, returning from a PC suspend state can add latency and create skipping.
– Other considerations that can interfere with Bluetooth can be found here.