Bluetooth Audio (A2DP) on Ubunto
Just a week ago, I make a revolution to my home computers, begin to use Ubuntu on my home notebook and say goodbye to Windows. I have used Linux system for a long time but this is just limit to the server environment. I didn't have any good impression with Linux desktop enivronment. One of the major reason was the user interface's friendliness and the look. Linux desktop is always ugly and difficult to use. However Ubuntu totally turned over my mind, it is robust stable, competent features, clean interface and easy to configure. One of the biggest concerns in this migration is to make sure all my regular tasks can still be done in the new platform. Bluetooth audio (A2DP) is supported by Ubuntu but unfortunately the configuration is not straight forward and friendly. Here by I will introduce a procedure called "pulse" copy from bluetooth linux website. I only tested this on Ubuntu 8.10 but it supposes to work on any Linux distribution.
1. Pairing your bluetooth headphone as usual uses the bluetooth utility in the notification area.
2. Create a text file ".asoundrc" in your home directory and put the following:
| pcm.bluetooth { type bluetooth device "00:00:00:00:00:00" } |
"00:00:00:00:00:00" is your bluetooth headphone MAC address. If you don't know the address, changing your headphone to pairing mode and execute "hcitool scan" to get the address.
3. Install package "pavucontrol"
| sudo apt-get install pavucontrol |
4. Create a script file in the following and put the file in any convenient place. You will use this file to connect or disconnect the bluetooth connection.
| #!/bin/sh index=`pactl list | grep -B 2 'Argument: device=bluetooth' | egrep 'Module #[0-9]+' | sed 's/[^0-9]//g'` if [ -z "$index" ]; then echo "load bluetooth module" pactl load-module module-alsa-sink device="bluetooth" else echo "unload bluetooth module: $index" pactl unload-module $index fi |
5. Turning on your headphone and run the script to make the connection. If successful, some number should be displayed.
6. Open "PulseAudio Device Chooser", clicks the icon in the notification area to open "Volume Control". In "Output Devices" tab, you should see some bluetooth device in the list. Click the down arrow icon and checks the "Default" checkbox.
7. Open "Sound" in system menu. In "Devices" tab, changes all the playback devices to "PulseAudio Sound Server".
Congratulation, you have finished the configuration and your bluetooth headphone becomes the default output source when it is connected. You can use the script file to turn on or off the headphone connection. The current implementation has some problem if the headphone connection is closed and your application is still playing the sound, most likely your application will be frozen as well. Actually the same thing is happened with my old day's Windows system. :P



