Bluetooth headphones problem (ubuntu 16.04)

Here goes yet another post about bluetooth problems... I have bluetooth headphones (Samsung Level U) and a laptop running ubuntu 16.04.
The headphones work perfectly when pairing with windows/android devices, and they connect automatically and without problems; but with ubuntu - there are always some problems.
Usually they work fine when I pair them with ubuntu the first time; however, each time after reconnect, I have to manually turn on bluetooth connection, then go to audio settings, select bluetooth headphones as audio sink, and then change the sink mode from telephony duplex to high fidelity playback (a2dp sink).
As if that isn't annoying enough, every time after my bluetooth headphones connect with any other device (like an android phone), the connection to Ubuntu starts to "fail" in random places. 50% of the time Ubuntu can't find my headphones in a list of bluetooth devices. 25% of the time it finds and connects well, but there is no sound and no bluetooth headphones in the list of audio sinks. 25% of the time there are headphones in the audio sink list, but they fail to switch modes from telephony duplex to a2dp sink (the buttons in Ubuntu work, but the mode isn't actually changed, and the sound remains awful).
As a result, every time after my headphones connect to any other device, I spend 3-5 minutes turning headphones on and off, turning bluetooth on and off, deleting and pairing them again, bouncing back and forth between audio sinks and playback modes, until I finally get them to work properly.
I have this problem for over a year now (ubuntu 14.04 before 16.04), and every month I try to google for solutions, but nothing ever actually works for me.
I've tried installing and reinstalling blueman, pavucontrol and pulseaudio; i've tried creating a pairing with blueman instead of Ubuntu default bluetooth settings; I've tried editing etc/pulse/default.pa; I've tried writing pulseaudio -k after reconnecting to headphones. Nothing of this worked - the only time I can get my headphones to work is with default ubuntu bluetooth settings, but every time they reconnect I have to go through the long procedure of getting them to work.

Please help!


Solution 1:

I have finally found the answer in this thread: No sound from bluetooth headset, but it's detected This script https://gist.github.com/pylover/d68be364adac5f946887b85e6ed6e7ae#file-a2dp-py just fixes the problem. Works flawlessly