#Setup
Let's Install the packages
sudo apt-get upgrade
sudo apt-get install bluez pulseaudio-module-bluetooth python-gobject python-gobject-2 bluez-tools
First, let’s go ahead and add our user pi to the Pulse audio group so we the user can play audio through it.
sudo usermod –a –G lp pi
Now, let’s go ahead and enable A2DP in our Bluetooth configuration. Run the following command:
sudo nano /etc/bluetooth/audio.conf
This will open the text editor nano with that config file. Add the follow text under [General]:
Enable=Source,Sink,Media,Socket
Save it.
Next, let’s modify the Pulse daemon configuration file to change its resampling method.
sudo nano /etc/pulse/daemon.conf
Look for the following line: resample-method = speex-float-3
If the line doesn’t have a ; in front of it, please put a ; there so it looks like:
; resample-method = speex-float-3
And then add the following line underneath that.
resample-method = trivial
Next find
; exit-idle-time = 20
And then add the following line underneath that.
exit-idle-time = -1
Before moving on, let’s also go ahead and rename our Bluetooth device (odds are you don’t want the name to be raspberry-pi0) as well as redefine the Bluetooth class device from 'Computer' to 'Portable audio device'. There are two locations you should modify.
sudo nano /etc/bluetooth/main.conf
Change the Name parameter. I chose to do a play on the Bplay.
Name = Bplay
Next, you’ll have to modify the config of your specific device. The directory is based on your Bluetooth device’s MAC address so just hit TAB when typing that out and you’ll find yours.
sudo nano /var/lib/bluetooth/[bluetooth mac address]/config
Edit the name directive again.
name Bplay
Let's now setup the auto-conenct scripts
sudo nano /etc/udev/rules.d/99-input.rules
There should be just a single line there that looks like:
SUBSYSTEM=="input", GROUP="input", MODE="0660"
Underneath it, let’s go ahead and add the following line:
KERNEL=="input[0-9]*", RUN+="/usr/lib/udev/bluetooth"
Save and exit.
Now let’s actually save that script that the above rule file is referencing. First check to see if a udev/ directory exists. Do sudo ls –la /usr/lib/udev
. If it doesn’t exist go ahead and create it like so: sudo mkdir /usr/lib/udev
sudo nano /usr/lib/udev/bluetooth
Copy and paste the contents of bluetooth-change.sh file.
Now let’s modify the permissions of the file to make it executable.
sudo chmod 774 /usr/lib/udev/bluetooth
Automating Bluetooth discovery and auto accepting connections
sudo nano /etc/init.d/bluetooth-agent
Go ahead and copy paste bluetooth-agent.sh into the text editor.
Save and exit nano.This script basically is just a standard start/stop script for Bluetooth discoverability. Go ahead and give the script execute permissions and then add it to the list of programs that start on start-up.
sudo chmod 755 /etc/init.d/bluetooth-agent
sudo update-rc.d bluetooth-agent defaults
#Additional Info's
To debug use pulseaudio -vvvv --log-level=debug
HI
/etc/bluetooth/audio.conf can i cange main.conf????
sudo nano /var/lib/bluetooth/[bluetooth mac address]/config cannot find it
there is setting but is empty
please help
thank you