Chinaunix首页 | 论坛 | 博客
  • 博客访问: 536805
  • 博文数量: 84
  • 博客积分: 6010
  • 博客等级: 准将
  • 技术积分: 2109
  • 用 户 组: 普通用户
  • 注册时间: 2006-09-25 14:02
文章分类

全部博文(84)

文章存档

2011年(10)

2010年(22)

2009年(16)

2008年(36)

我的朋友

分类: LINUX

2008-11-03 15:33:57

Note: These instructions will . This will not work with Bluez 4 or above, included with Ubuntu 8.10+. PulseAudio is also set to get automatic A2DP configuration through a Google SoC project very soon.

Wires are for suckers. In this day and age, wireless headphones are where it’s at. While we may not be able to drop the power cord for the time being, we can at least get rid of annoying, east-to-tangle headphone wires by using a Bluetooth headset.

But no, you say, Bluetooth audio sounds horrible. Well my friend, you were probably using a low-quality profile such as HSP. If you want full-quality stereo profile, you want A2DP.

The first requirement is a Bluetooth adapter on your PC or laptop. The second is a Bluetooth headset that supports the A2DP profile, such as the headphones. Most earbud headsets don’t support A2DP, so you’re out of luck if you own one. Finally, you’ll need the package installed.

Now we’re on to the actual setup. A lot of A2DP tutorials out there require you to install some custom system service or do some weird voodoo dance to get them to work. The reference I have found so far has worked every time for me. Most of this is simplified , so if you are looking for additional setups I suggest you look there after trying this.

Feeling lazy and want me to do this all for you? Well, today is your lucky day. I’ve made a custom script that will automatically configure it all for you.


(Paranoid? .)

Simply run it as a normal user and follow all of the steps:
bash a2dp.sh

It will automatically download the connection script and ALSA configuration file to get the job done. All of the scripts will be installed into ~/.a2dp, with an autostart file in ~/.config/autostart.

After you run it, you probably want to use it with a media player. All you need to do is tell your music/video player to use the “bluetooth” output device. Some players, like Audacious and Amarok, let you specify this in their preferences. GStreamer-based applications, like Banshee and Rhythmbox, rely on GStreamer to output to the right device. To do this, a “toggle” script was included with the script above: ~/.a2dp/toggle.sh. To get the most use out of it, add it to your panel.

In GNOME, right-click a blank space and select Add to Panel, then Custom Application Launcher. Fill it in with the settings below. You must use a full path to the script. To see any dialogs, you must have . It will work without them, but there will be no notification.

To switch to and back from your Bluetooth headphones and speakers, just give it a click:

(Again, for non-GStreamer apps, this step is not required. Just set the ALSA device to “bluetooth” in the player preferences.)

Fire up your favorite music player and enjoy.

AVRCP (Remote Control)

Some headsets may have control buttons, such as pause, next, and rewind. These may work by default on some desktops, but if it doesn’t, there is a good chance you don’t have uinput enabled. Open the file /etc/modules with root permissions and add the line with uinput at the end. Save the file and reboot, and AVRCP should work.

Comments (75) to “A2DP (Stereo Bluetooth Headset) on Linux”

  1. Is there any way (im sure there is :) ) how to improve sound quality ???
    Please let me know (using my mail :) )

  2. I have a headset that needs to be paired using the key 0000 (it’s a Kyocera headset if that matters) before pairing can actually complete. How can I modify your scripts to include using the key?

  3. shanks:

    As long as you have some sore of Bluetooth manager installed (ie, bluez-gnome or gnome-bluetooth) the passkey entry will automatically appear the first time you try to play a song.

  4. Thank you, brilliant script. It worked out of the box on my Gutsy installation in combination with the Jabra BT 620s.
    Is there any way to use the remote control functions? I can’t find the “Blue Remote” Plug-in for Rhythmbox.

  5. Andreas:

    The control functions use AVRCP, a profile that isn’t yet supported by the bluez-alsa package (or I’m just not looking hard enough).

  6. One word: thank you. OK, two words.

    I had to manually type “bluetooth” into audacious. (And restart it, but my amd64 build has been having issues that way–not your fault.)

  7. Ive installed the application above, everything has installed properly, although when i go to test the bluetooth headset(in sound settings) as i have no other way, it does have a faint hiss sound. But soon after my whole computer crashes.Im running 7.10 Gutsy

    Any advice would appreciated

    Thanks

  8. Very nice. I spent all day trying to get this working, and your script worked right away.

    Thank you, and I hope you get visited with appropriate karma.

    Pat

  9. I made little change in your toggle.sh script for mplayer. I use geexbox script mp_set_option and it isn’t hard to use it (it use sed with one if). So it is only idea how to make your great script perfect :)

  10. This is excellent! I want the last 2 days of my life back. Got my new Insignia NS-BTHDP working in minutes in Gutsy.

    So far I can get the movie and audio players working no problem but I have yet to get the headset to be the default system sounds or even more importantly for me for firefox flash-plugin use the bluetooth… any pointers?

  11. Thank you so much! one step closer to not having to use vista.

  12. [...] to Jacob over at FOSSwire I now have my headphones working and a easy way to switch between them and my internal speakers. I [...]

  13. Hi, I’ve installed the script, but the audio is not being routed to my headphones… what do I do. I’m using ubuntu on an ibm t60

  14. It’s working!!! I was previously using Blueman Bluetooth-applet & Audacious-combo. This is working now also with other applications!!! Wuhuu!

  15. Except… When I manyally change next song, it says “xine was unable to initialize any audio drivers.”

    And in other occations “audio output unavailable the device is busy”

    Darn, so close…

  16. it’s not working for me.
    I get this error message:
    00:16:20:ff:f0:5f
    Installing .asoundrc Bluetooth device… done.
    Installing autostart script in ~/.config/autostart… done.
    Preparing optional GStreamer support…-e done.

    Starting up…
    Traceback (most recent call last):
    File “a2dp.py”, line 11, in
    sink.Connect()
    File “/var/lib/python-support/python2.5/dbus/proxies.py”, line 63, in __call__
    return self._proxy_method(*args, **keywords)
    File “/var/lib/python-support/python2.5/dbus/proxies.py”, line 135, in __call__
    **keywords)
    File “/var/lib/python-support/python2.5/dbus/connection.py”, line 603, in call_blocking
    message, timeout)
    dbus.exceptions.DBusException: org.bluez.audio.Error.Failed: Stream setup failed
    All set up! You will need to log out for the changes to take effect.
    -e Trust me, it won’t work unless you do.

    Thanks for reading FOSSwire!

    Any ideas?

    [Try installing bluetooth-alsa. -Jacob]

  17. awesome. your script is working perfectly. I’d faced the same error in comment #16, but i resolved it by starting bluetooth service in Fedora 8 (/etc/init.d/bluetooth start)

  18. I get the same error as Finnish…. does anyone have any idea why?

  19. Jacob, it was already installed :(
    I checked the system logs. It has problems with authentication. My a2dp device is a Sony Ericsson MBS-100. It DOES support a2dp. so i don’t really understand it.

    Time to learn Python :)

  20. That’s awesome, dude! It works

  21. It works perfect with my Sonyericsson HBH-DS970.
    Thanks Jacob

  22. For Lukas Stejskal,

    Install the latest Alsa package. Mine sounded like the headphones were full of mud until I did. Install the whole set not just the driver.

    Jacob,

    Thanks for the script. I just loaded up Gnome after using KDE for years and had no idea how to get Gstreamer to see bluetooth audio.

    Thanks, -j

  23. [...] checked out bluetooth-alsa again - came across this site to ease the installation of a2dp (stereo bluetooth headset) on Linux. Worked incredibly well - comes with a nice script to toggle between speaker/headset. VLC & [...]

  24. Thanks for these scripts. They work great. I had to change the permissions on the python script, and I added “#!/usr/bin/python” to the top of it, so it could just be called without the python. But that’s just me being picky. :)

  25. [...] used the code from this blog to get it [...]

  26. This is great except that I can’t figure out how to get audio from the flash plugin in Firefox to send audio to bluetooth. It still uses the Intel soundcard on my laptop. I’ve tried figuring out how to change my default ALSA device in Gnome, but I’m not sure I’m doing it right. I have the custom playback device selected in Sound playback in the Sound Preferences, but that doesn’t seem to have worked. Any thoughts?

  27. Thanks a ton..:))

    it working superbly.. :)

  28. I’m having the same problem as Ken above. I can get sound via bluetooth headphones for rhythmbox and totem player. flash videos in firefox still play over my Intel audio card ( Intel Corporation 82801G (ICH7 Family) High Definition Audio Controller) on Dell D620 laptop.

    Also, my pidgin sound alerts no longer work if I’m using bluetooth headphones. If in pidgin, the sound method is “Automatic” and I run the toggle.sh script, sounds stop in pidgin. But, if I set the Sound Method to “ALSA “, in pidgin, sound will play over the internal speakers, and not the bluetooth headphones.

  29. Well… why do you have to put ‘\n’ in echo statements ?
    It won’t work…
    Haven’t checked the script if it works. Will let you know once i do.
    Thx

  30. I put the following in my ~/.asoundrc and firefox hangs:

    pcm.!default {
    type bluetooth
    device 00:18:E4:0C:4F:29
    profile “hifi”
    }

  31. [...] [...]

  32. Really? Just that easy? Someone should tell Microsoft how it’s done. Ubuntu Linux running on my laptop now officially has better hardware support than the OEM installed Vista!

  33. Thanks, worked perfectly on Hardy on my Dell Inspiron 6000 Laptop. Only issue is I have to restart Rhythmbox when switching

  34. I have tried at least 5 a2dp tutorials for my Bluetooth Hifi and none have been successful - yours worked first time. Thanks so much!

  35. It’s work well on a Dell Inspirion 1525 with headset Dell DH200 and Ubuntu 8.04.
    Thank you Jacob

  36. Didn’t work for me. First I had to edit .wgetrc to comment out verbose mode, then I had to install some python-dbus support, and finally a2dp.py died with

    Traceback (most recent call last):
    File “a2dp.py”, line 9, in
    path = audio.CreateDevice(mac)
    File “/var/lib/python-support/python2.5/dbus/proxies.py”, line 68, in __call__
    return self._proxy_method(*args, **keywords)
    File “/var/lib/python-support/python2.5/dbus/proxies.py”, line 140, in __call__
    **keywords)
    File “/var/lib/python-support/python2.5/dbus/connection.py”, line 607, in call_blocking
    message, timeout)
    dbus.exceptions.DBusException: org.bluez.Error.ConnectionAttemptFailed: Host is down

    Surely the headset is on. ???

  37. PS: Adding the headset address and pin to

    /var/lib/bluetooth//pincodes

    did the trick. See /usr/share/doc/bluez-utils/README.Debian .
    But I still have to run the a2dp.py script again and again.

  38. PPS: The file is

    /var/lib/bluetooth/XX:XX:XX:XX:XX:XX/pincodes .

  39. BROKEN!!!

    I ran your script and get this: Getting a2dp.py connection script…Cannot specify -r, -p or -N if -O is given.
    Usage: wget [OPTION]… [URL]…
    done.

    I checked your script and it appears you are using some wget options that fail in fedora 9… HELLLP!!!!

  40. Maybe it helps if you temporarily rename the .wgetrc file in your $HOME directory?

  41. [SOLVED] dbus.exceptions.DBusException: org.bluez.audio.Error.Failed: Stream setup failed

    I had this problem after an automatic kernel update and trying to reconfigure my headset. I had to delete the bonding with my headset and then rebond and this fixed my problem.

  42. Your are magician :)Thanks

  43. I have a Parrot Boombox. Does any one know how to configure it. I have tried the steps above to no avail.

  44. Jacob!!!! We need more people like you!!! I spent hours and hours of efforts… well… maybe im exaggerating, but I worked a lot trying to use my hbh-ds970 from sony, and now Ihave this great script doing it so simple… Thnx a lot from Argentina!!!!

  45. Brilliant!! Works great on Ubuntu 8.04! I’ve been fighting a lot with this using earlier Bluez releases. Thanks to the Bluez project for adding a2dp and (finally) some decent documentation. And thanks to Jacob for making it so easy.

  46. Cool! Works perfectly for my i.Tech BlueBAND R.
    Playing music using Rhythmbox on Ubuntu Hardy

  47. As most of the above who’ve tried, I wasted a lot of time trying to get it to work and then I stumbled upon your post. Worked first time. The rest as they say is history.

  48. Your script works great. Thank you! However, what is disappointing is that I can’t listen to music over a2dp and at the same time use my bluetooth mouse. The music almost stops - one second of music comes out of the headset about every 15 seconds. On my windows boot, hifi music and mouse work together without any problems. Is this because of the linux drivers?? Has anyone noticed such an interference as well?

  49. For Bluetooth Mouse and A2DP support at the same time edit your /etc/bluetooth/hcid.conf:

    Change “lm accept;” to “lm accept,master;”
    and change “lp rswitch,hold,sniff,park;” to “lp hold,sniff,park;”

    Now it should work. At least for me :-)

  50. my fault: “lm accept;” should be changed to “lm master;”

    Cheers

  51. Very well done, thanks for sharing

  52. Works great with my Jabra BT8010! It was all a matter of minutes. I have tried to get it to work yesterday the whole day long! :q After trying it with several guides today i tried it with your script and it works like a charm.
    I’m using Kubuntu Hardy.

    Thank you very much for this script!!!

    Tomi

  53. Hi, I have passed a night in order to find a way for my HBH-DS970. No solution until I found your script.
    My OS is Ubuntu 8.04. I have just do “sudo bash /Bureau/a2dp.sh”.
    Thank you very much.

    Have a nice days.

  54. Thanks Jacob, was pulling my hair out trying to get a Tevion BT USB adaptor/Nokia BT-H to work on Hardy…..but they’re going great with Rythmbox look forward to trying the other apps out now.

  55. Ran the install script with no problems on Ubuntu Hardy 8.04. But when I toggle to bluetooth, Rythmbox won’t play at all. If I test the output using the “sound” system tool I get:

    “audiotestsrc wave=sine freq=512 ! audioconvert ! audioresample ! gconfaudiosink profile=music: Could not open audio device for playback.”

    Any ideas? Trying desperately to get my Dell BH200 working!

  56. Can you tell me what I am missing with dbus? Thanks.
    Starting up…
    Traceback (most recent call last):
    File “a2dp.py”, line 7, in
    bus_id = manager.ActivateService(’audio’)
    File “/usr/lib/python2.5/site-packages/dbus/proxies.py”, line 64, in __call__
    return self._proxy_method(*args, **keywords)
    File “/usr/lib/python2.5/site-packages/dbus/proxies.py”, line 136, in __call__
    **keywords)
    File “/usr/lib/python2.5/site-packages/dbus/connection.py”, line 607, in call_blocking
    message, timeout)
    dbus.exceptions.DBusException: org.bluez.Error.NoSuchService: No such service

  57. Thanks for your great luck gift, I will reboot to have a try

  58. Thanks for some great scripts. Word of note: If you have OpenSUSE 10.3 or any other distro that uses GConf2 you need to edit the .a2dp/toggle.sh file to use gconftool-2 otherwise it will never switch the output.

  59. I’ve been trying to get my Motorola S9 headset to work with Ubuntu for ages. Thank you so much for sharing this script with us!! It work flawlessly.
    You kick ass! :D

  60. Thanks for the script. its great. I am however having trouble with my bt8010. the music starts and then stops after 20 - 30 seconds. Any thoughts? ‘m running ubunte eee

    Thanks in advance!

  61. bump …

    more info, I’m using the smk nano dongle with edp

  62. Very very nice script. Thank you. It still works great in Hardy Heron. I just wish I could get it working with Ekiga.

  63. Guys provide any clues on this… I’m stuck up in configuring this bluetooth device.

    ===================
    We’re now going to scan for a bluetooth device. Please put your headset in pairing mode and press Enter.

    Scanning …
    00:1A:7D:0E:55:C2 BSH01
    Copy the address of your headphones above and paste it below:
    00:1A:7D:0E:55:C2
    Installing .asoundrc Bluetooth device… done.
    Installing autostart script in ~/.config/autostart… done.
    Preparing optional GStreamer support… done.

    Starting up…
    Traceback (most recent call last):
    File “a2dp.py”, line 9, in
    path = audio.CreateDevice(mac)
    File “/usr/lib/python2.5/site-packages/dbus/proxies.py”, line 68, in __call__
    return self._proxy_method(*args, **keywords)
    File “/usr/lib/python2.5/site-packages/dbus/proxies.py”, line 140, in __call__
    **keywords)
    File “/usr/lib/python2.5/site-packages/dbus/connection.py”, line 622, in call_blocking
    message, timeout)
    dbus.exceptions.DBusException: org.bluez.Error.ConnectionAttemptFailed: Permission denied
    All set up! You will need to log out for the changes to take effect.
    Trust me, it won’t work unless you do.

    Thanks for reading FOSSwire!
    [yehiya@yehiya-pc Download]$

    ====================

  64. Guys please help me in sorting out this issue.
    I even tried executing this script in root also.
    Still getting the same error

    ===========================
    Getting a2dp.py connection script… done.

    We’re now going to scan for a bluetooth device. Please put your headset in pairing mode and press Enter.

    Scanning …
    00:1A:7D:0E:55:C2 BSH01
    Copy the address of your headphones above and paste it below:
    00:1A:7D:0E:55:C2
    Installing .asoundrc Bluetooth device… done.
    Installing autostart script in ~/.config/autostart… done.
    Preparing optional GStreamer support… done.

    Starting up…
    Traceback (most recent call last):
    File “a2dp.py”, line 9, in
    path = audio.CreateDevice(mac)
    File “/usr/lib/python2.5/site-packages/dbus/proxies.py”, line 68, in __call__
    return self._proxy_method(*args, **keywords)
    File “/usr/lib/python2.5/site-packages/dbus/proxies.py”, line 140, in __call__
    **keywords)
    File “/usr/lib/python2.5/site-packages/dbus/connection.py”, line 622, in call_blocking
    message, timeout)
    dbus.exceptions.DBusException: org.bluez.Error.ConnectionAttemptFailed: Permission denied
    All set up! You will need to log out for the changes to take effect.
    Trust me, it won’t work unless you do.

  65. Wonderful! Thank you for sharing!

  66. Hello,

    The script works perfectly for almost all my multimedia software, but Skype not.
    I use Skype very often for my business, but, as I install the script, the Skype block times. And if I open the configure of Skype and click “voice device”, It looks like crash for 5 min, and then it can show the detail. And any message will wait 5 min then it can send out.

    Do you have any ideas?

  67. With my check, If my bluetooth headphone close, the skype works wrong. I think the skype will try to send voice to bluetooth, but it can not find it.

    How to avoid of that? I don’t want open bluetooth headphone all the time.

  68. And in skype, the voice device set as “default device”. I don’t know why it check all the voice device.

  69. Un millon de gracias!!
    (A million thanks!!)
    Run with my nokia-501. Fast and easy. :D

  70. [...] Enlace: Fosswire [...]

  71. I spent hours trying to figure out use of my Jabra headset in Ubuntu - your script worked immediately. Rhythmbox works perfectly, though I still haven’t found where to change to Bluetooth in Amarok.

  72. Great script.. Spent an entire day trying to get my iTech Blueband R to work without success, until I tried this script. I finally got sound out from my headset… Except for 1 problem, the sound comes out “choppy.” I’m not sure if its the BT signal problem or anything but playing music or video, sound comes out in bits (1 to 2 seconds intervals) from my headset. Hope anybody help :-)

    Thanks

  73. Receiving the following error:

    Traceback (most recent call last):
    File “a2dp.py”, line 11, in
    sink.Connect()
    File “/var/lib/python-support/python2.5/dbus/proxies.py”, line 68, in __call__
    return self._proxy_method(*args, **keywords)
    File “/var/lib/python-support/python2.5/dbus/proxies.py”, line 140, in __call__
    **keywords)
    File “/var/lib/python-support/python2.5/dbus/connection.py”, line 607, in call_blocking
    message, timeout)
    dbus.exceptions.DBusException: org.bluez.Error.Failed: Stream setup failed

    Any ideas?

    [ Make sure your headphones are on and your system's Bluetooth is enabled. -Jacob ]

  74. Thank you so much for an easy and working install!

    The one thing that had me stomped for a short time: after switching from speakers to bluetooth you need to restart rhythmbox before audio is piped to the new sink.

  75. [...] Earlier this year, I showed you how to get high-quality A2DP audio streaming to your Bluetooth headphones. And while that method of connecting your headphones to a music player does work fine, it really only works with media players and anything else set up to specifically play to your headset. What if you want to watch a Flash video with A2DP audio? How about play a game of Nexuiz through the headset? Well, with that implementation, you can’t. [...]

阅读(2000) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~