Saturday, September 10, 2011

How to: Bluetooth Speakers without Pulseaudio

About 3 months ago I have purchased a Bluetooth Speakers set. I chose the Creative Labs D200, which provide me with nice tunes compared to the prices. The speakers worked out of the box with my Bluetooth adapter. Pulseaudio also makes life easier to switch between the laptop's own speaker to the Bluetooth speakers. However, I get irritated sometimes with pulseaudio, and I was looking for an alternative solution.

After researching a few different sources I have come up with my own flavor of solution, which I document here for future benefit of myself and others.



The first step included removing all the components of Pulse-Audio, and installing the bluez-alsa packages:
apt-get remove pulse-audio
apt-get install bluez-alsa
then edit the file .asoundrc:
 linuxpixie@laptop:~$ cat .asoundrc 
pcm.bluetooth {
    type bluetooth
    device 00:02:3C:26:BA:87 # change this MAC address using the command "hcitool scan"
    profile "auto"}
pcm.!default {
   type hw
   card 0
   device 0
}
Now pair your device to the laptop, using hcipair command or gnome-blue-tooth-applet or blueman-applet, what ever you use.
Now you need to tell gstreamer to use the bluetooth device as  the audio sink. This is basically done with the following command:
gconftool-2 -t string -s /system/gstreamer/0.10/default/musicaudiosink \
"alsasink device=bluetooth"
I modified a small script to make the switching to bluetooth sound and backward. This script lies in my ~bin/ directory.
linuxpixie@laptop:~$ cat bin/audioswitcher.sh 
#!/bin/bash
state=`gconftool-2 --get /system/gstreamer/0.10/default/musicaudiosink |  
cut -d\  -f1`
if [ $state == "autoaudiosink" ]; then
    gconftool-2 -t string -s /system/gstreamer/0.10/default/musicaudiosink \
    "alsasink device=bluetooth" 
    zenity --info --title="GStreamer" --text="Switched to bluetooth speakers"
else
    gconftool-2 -t string -s /system/gstreamer/0.10/default/musicaudiosink "autoaudiosink"
    zenity --info --title="GStreamer" --text="Switched to laptop speakers"  
fi
Don't forget to make the script executable, with:
linuxpixie@laptop:~$ chmod +x bin/audioswitcher.sh   
Now you can just call the script use gnome-launcher, a keyboard shortcut or just using the terminal.
One Last thing. VLC is a very popular player which I use too. However, this solution does not work for VLC, since it does not use Gstreamer. So, the solution, is to edit the VLC config file found
.config/vlc/vlcrc
.
[alsa] # ALSA audio output

# ALSA Device Name (string)
#alsa-audio-device=hw:0,0
#alsa-audio-device=default
alsa-audio-device=bluetooth
As a nice bonus, if your Bluetooth adapter is ON and available, you don't need to pair it with laptop when playing with VLC. VLC will hang for about 4 second, waiting for the Bluetooth speakers to turn ON, and will pair automatically, and then the music will be played automatically through the Bluetooth speakers. If the Bluetooth devices is not found, VLC will play the music through the Laptop speakers.

UPDATE (March 2012):
Upgrading from bluez 4.96 to 4.98 broke this setup and I could not find a solution until I reported a bug on that issue. The maintainer send me a solution:

addding following into [General] section of /etc/bluetooth/audio.conf

Disable=Media
Enable=Socket
A more updated version of the script, can be found in my github. This Updated version is also working on mate-desktop.

40 comments:

Anonymous said...

It gives pretty good sound when all the speakers are used together, it sounds like crap if only the front left/right speakers are used.

bluetooth speakers

Unknown said...

I have been through the web and find this here. It is pretty useful. It actually works. Thanks for sharing.
Bluetooth Speakers

Anonymous said...

What are the best bluetooth speakers for this price range?
wifi speakers

John Adam said...

Really!!! I am very impressed after reading this blog. thanks for providing deep information for
fade alan walker

Anonymous said...

If you don’t do much talking on your mobile phone, you’re probably okay with the earbuds that came with it. And if you listen to a lot of music on that phone, with only the occasional call, you might want to consider stereo Bluetooth headphones with a microphone .But a good mono Bluetooth headset is a great accessory if you speak on the phone frequently and want the convenience of having your hands free. It’s also an important item if you need to be sure that your voice sounds clear to the person on the other end, without too much wind or other background noise. latestone.com And if you spend a decent amount of time talking on the phone, you don’t want to stay tethered to your handset by a wire, or to hold the phone with your shoulder while you talk—the latter is terrible for your neck and back.

Anonymous said...

It's really a nice and helpful piece of information. I'm glad that you shared this helpful info with us. Please keep us informed like this.
ceiling speaker amplifier

Jr. Williams said...

I am really very agree with your qualities it is very helpful for look like home. Thanks so much for info and keep it up.
Stonelove J - Urkel video

Jhon Marshal said...

There are certainly a lot of details like that to take into consideration.
ceiling speaker amplifier

Sức khỏe vàng said...

Nice!

Jr. Williams said...

This is a brilliant writing and very pleased to find this site. I couldn’t discover to much different information on your blog. I will surely be back again to look at some other important posts that you have in future.
erato audio

John Adam said...

I definitely appreciate your blog. Excellent work!
RMP - FLEXIN Music Video

Jr. Williams said...

I guess there's always an easier way ...
Drummer

Unknown said...

I definitely appreciate your blog. Excellent work!
No Control by Laura Mendes

Anonymous said...

I would be grateful if you continue with the quality of what we are doing now with your blog ... I really enjoyed it
edm violinist

Anonymous said...

Your Post is very useful, I am truly happy to post my note on this blog . It helped me with ocean of awareness so I really consider you will do much better in the future.
Borderline feat. Joyce Sterling

Jr. Williams said...

I definitely appreciate your blog. Excellent work!
Amie Penwell - Dogfight On The Moon

John Adam said...

Resources like the one you mentioned here will be very useful to me! I will post a link to this page on my blog.
Radiohead Cover Creep by Chonna Cristelle

Jr. Williams said...

Cool blog you got here and thank you for the valuable info.
Mr. Shammi_Time Machine (Official Video)

Jr. Williams said...

I am really very agree with your qualities it is very helpful for look like home. Thanks so much for info and keep it up.
First Music Video Villain- KD

Jhon Marshal said...

Thank you for the helpful post. I found your blog with Google and I will start following. Hope to see new blogs soon.
Michael Blu Music

John Steven said...

I have to say this has been probably the most helpful posts for me. Please keep it up. I cant wait to read whats next.
Sensory friendly theater New Jersey

Jr. Williams said...

Wow, what a blog! I mean, you just have so much guts to go ahead and tell it like it is. Youre what blogging needs, an open minded superhero who isnt afraid to tell it like it is. This is definitely something people need to be up on. Good luck in the future, man
Sleeping

Jhon Marshal said...

Thank you for the helpful post. I found your blog with Google and I will start following. Hope to see new blogs soon.
Can't Stop the feeling by Justin Timberlake

Jhon Marshal said...

Like your Posts.Thanks Keep Posting.
Paul Maged - "The Wild" (Official Music Video)

Jhon Marshal said...

I would be grateful if you continue with the quality of what we are doing now with your blog ... I really enjoyed it
Changing Chords

Jhon Marshal said...

This article has great reference value, thank you very much for sharing, I would like to reproduced your article, so that more people would see it.
Shows2Go App

Jr. Williams said...

I guess there's always an easier way ...
No Other Bagger by Chiro Music video

Jr. Williams said...

Post is very informative,It helped me with great information so I really believe you will do much better in the future.
Tory Lanez performing live

John Klain said...

Spot on with this article, I really think this website needs more attention. I'll probably be back to read more, thanks for the info.
Ev Vinyls - The Rush Music Video

Jhon Marshal said...

Thanks for sharing info. Keep up the good work...We hope you will visit our blog often as we discuss topics of interest to you
pop music Artist Ksenia Valentis

Jr. Williams said...

Spot on with this article, I really think this website needs more attention. I'll probably be back to read more, thanks for the info.
Black Rock Revival-If You Want It

Jhon Marshal said...

Spot on with this article, I really think this website needs more attention. I'll probably be back to read more, thanks for the info.
Native Instruments

Jr. Williams said...

Thanks for sharing info. Keep up the good work...We hope you will visit our blog often as we discuss topics of interest to you
English Language for movies and songs

Jhon Marshal said...

I think most people would agree with your article. I am going to bookmark this web site so I can come back and read more articles. Keep up the good work!
Dammy Ari Give Ya (Music Video Song)

Jhon Marshal said...

Valuable information! Looking forward to seeing your notes posted.
Electric Love by Funeral Strippers

John Adam said...

I would be grateful if you continue with the quality of what we are doing now with your blog ... I really enjoyed it
Live Your Life to the Fullest

Jhon Marshal said...

Thank you for the helpful post. I found your blog with Google and I will start following. Hope to see new blogs soon.
Beyond the Sea

Alston Kane said...

Thanks for the information and links you shared this is so should be a useful and quite informative! 


Official Music Video for Passion

Albert Stone said...

This blog is having the very nice information about music. Here we can have all the information about it.

SHORT FILM

Unknown said...

Liztek is the Manufacturer and best Seller of Multi Color portable bluetooth Speaker, Ultra Portable Bluetooth Speaker, Bluetooth Receiver and Bluetooth Shower Speaker on Amazon and Walmart Marketplace in the USA.