Sunday, January 11, 2009

A2DP (Stereo Headsets) on Linux

I've never got it to work the first time, I always keep searching, trying, and failing until I finally find a way that works.

This time I decided to share it with people so they won't go through this, it's also easier than the rest, here's what you have to do:

First of all, pair your headset with your computer.

Create a file in your home directory called .toggle.sh

Inside that file put the following:

#!/bin/bash

state=`gconftool --get /system/gstreamer/0.10/default/musicaudiosink | cut -d\ -f1`

if [ $state = "autoaudiosink" ]; then
gconftool --type string --set /system/gstreamer/0.10/default/musicaudiosink "sbcenc ! a2dpsink device=XX:XX:XX:XX:XX:XX"
zenity --info --title="GStreamer" --text="Switched to BT headphones."
else
gconftool --type string --set /system/gstreamer/0.10/default/musicaudiosink "autoaudiosink"
zenity --info --title="GStreamer" --text="Switched to speaker output."
fi

echo musicaudiosink set to `gconftool --get /system/gstreamer/0.10/default/musicaudiosink`


replace XX:XX:XX:XX:XX:XX with the address of your headphone, you can get that by setting your headphone to be visible and running

hcitool scan


That's it :)

This script toggles between your bluetooth headset and your speakers and shows you a dialog.

You can add a launcher to your panel.

Right click on the panel, add to panel, custom launcher, and for the command enter:

sh /home/ljuwaidah/.toggle.sh


of course, replace ljuwaidah with your username.

To get your buttons (play, pause, prev, next, etc) to work, edit /etc/modules and add uinput to the end of the file.

Hope this helps :)

This is taken from this post on board4all: http://www.board4all.cz/showthread.php?t=134759.

PS: this is better 'cause it actually switches between the speakers and headphones unlike what's mentioned in that post where you have to go to your sound preferences to switch back to speakers (they had a bug in the script: they used == instead of =). Also, I found that you don't need the other files.

No comments: