b.ramus
Posts: 3
Joined: Thu Feb 06, 2014 6:41 pm

Bluetooth audio streaming

Thu Feb 06, 2014 8:46 pm

Hi everyone,

I'm new on this forum and I would like to share a little project I made to stream audio content from a bluetooth source (a phone for example) to the raspberry jack output.
I spent a lot of time to get information from different sources and use a part of each to make my raspberry doing what I wanted. I didn't find any complete tutorial to do it and I think it can be interesting for people who want to have the same use of their raspberry PIs.

I recently saw some wireless bluetooth speakers that are able to play music from a remote device using a standard named A2DP (Advanced Audio Distribution Profile). A2DP is a bluetooth profile that many devices support in a native way.
This system is really interesting because you can easily listen music everywhere, just keeping your portable speaker with you. Nevertheless, when your are at home and have a complete audio system (audio amplifier with speakers), it's quite disapointting to listen music on a little portable speaker as you could have a much better sound with your audio system. You have another solution that is to connect your phone with an adapted jack wire but in this case, your phone is plugged in your audio system and you can't freely use it at the same time : it's not very practical...

The advantage of this bluetooth standard comparing to other audio streaming solutions using Upnp protocol for example is that you simply redirect your phone audio output and use what you want to play music. In other terms, your are not dependent of a particular player or application to listen music on your phone : the only condition is that the thing you use makes sound. I was particularly interested in this solution because I use a lot online music providers such as Spotify or Deezer, so I couldn't easily use Upnp solutions because my music is not saved on my phone as classical Mp3 files. With this solution you can play sound from any source on your phone : a particular application, your internet browser, your local Mp3 player, a call you receive...

So let me introduce my solution.

First of all the required things :
  • a raspberry Pi (I have a raspberry type B but I think it can also work with a type A)
  • an SD card with the lastest raspbian distribution (I use 2013-09-25-wheezy-raspbian)
  • a compatible USB bluetooth adapter (I bought one very simple from the french provider "Boulanger" which perfectly works whithout any additionnal driver. The internal bluetooth chip is made by Cambridge Silicon Radio. A list of compatible hardware is available at the following address : http://elinux.org/RPi_VerifiedPeripherals)
  • a bluetooth audio device which supports the A2DP audio profile. I personnaly use my phone to stream some music : a samsung galaxy s4 which runs android 4.3. I think that most of android phones support it. I haven't tried with apple devices or Windows phones but it probably works. Even some older phones should work.
  • an headset or a jack wire (connection to an audio amplifier input) to get sound from the raspberry jack ouput
  • some basic knowledge of linux (use of terminal commands, edit files)
And... some good patience !

Remark : if you already have others USB devices connected to your raspberry, you can use an external powered usb hub. It can solve some problems if your devices require important power to work : the power that the raspberry can provide your usb devices with is limited. If you only use a bluetooth adapter, it is not necessary.

I assume that you have a ready-to-use raspberry pi and you know how to access it (with a screen, keyboard and mouse or directly from another computer thanks to an ssh connection). If not, there are a lot of good tutorials on the internet and I'm sure you will manage to do it (Google is your friend :-) ).
If you already have a raspbian distribution on your raspberry and you customized it with a lot of personnal settings, I suggest you to re-install a clean version : it will prevents you from facing some addtionnal configuration problems (you can save your current image before trying it).

So the first thing you have to do is to plug your bluetooth USB adapter and to switch on your raspberry. Your adapter should begin to blink if it is equiped with an activity LED.

Then, you have to log on your raspberry as the default "pi" user and to open a terminal (if you use a ssh connection you are already on a terminal window) : all will be done from it !

1. Install required packages

Update your repositories list to make sure you will find all the required packages :

Code: Select all

sudo apt-get update
We will use in this solution a particular linux component called pulse-audio which is responsible for the sound management and another one called bluez for the bluetooth management.
Download and install the bluez component, the pulse-audio bluetooth module and some other required dependencies :

Code: Select all

sudo apt-get install bluez pulseaudio-module-bluetooth python-gobject python-gobject-2
2. Change audio default settings

Add the default user "pi" to the lp group (you will be able to see bluetooth sources and to change some bluetooth settings) :

Code: Select all

sudo usermod -a -G lp pi
Change the default bluetooth audio settings :

Code: Select all

sudo nano /etc/bluetooth/audio.conf
Add/Complete the following line in the [General] section :

Code: Select all

Enable=Source,Sink,Media,Socket
Change the resampling algorithm from the pulse-audio configuration file :

Code: Select all

sudo nano /etc/pulse/daemon.conf
Add the following line after the commented example ";resample-method = speex-float-3" (don't use the ";" symbol which indactes a commented setting) :

Code: Select all

resample-method = trivial
Reboot your raspberry to apply settings :

Code: Select all

sudo reboot
3. Make sure your bluetooth adapter is working

Display the current bluetooth configuration :

Code: Select all

sudo hciconfig -a
You should see your bluetooth usb adapter reference on the hci0 interface as following :

Code: Select all

	hci0:	Type: BR/EDR  Bus: USB
	BD Address: XX:XX:XX:XX:XX:XX  ACL MTU: 192:8  SCO MTU: 64:8
	UP RUNNING PSCAN 
	RX bytes:2035 acl:0 sco:0 events:119 errors:0
	TX bytes:467 acl:0 sco:0 commands:50 errors:0
	Features: 0xff 0xff 0x8f 0xf8 0x18 0x18 0x00 0x80
	Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
	Link policy: RSWITCH HOLD SNIFF PARK 
	Link mode: SLAVE ACCEPT 
	Name: 'raspberryMedia'
	Class: 0x4e0100
	Service Classes: Networking, Rendering, Capturing, Telephony
	Device Class: Computer, Uncategorized
	HCI Version: 1.2 (0x2)  Revision: 0x7c5
	LMP Version: 1.2 (0x2)  Subversion: 0x7c5
	Manufacturer: Cambridge Silicon Radio (10)
You can see the bluetooth address of your USB adapter on the line BD Address: XX:XX:XX:XX:XX:XX

You can change the name of your USB bluetooth adapter as it will be visible by remote devices from the following file, where XX:XX:XX:XX:XX:XX represents the bluetooth address of your USB adapter :

Code: Select all

sudo nano /var/lib/bluetooth/XX:XX:XX:XX:XX:XX/config
Remark : if you change your adapter name, it will be active on next reboot

Another configuration file can be interesting :

Code: Select all

sudo nano /etc/bluetooth/main.conf
You can use some other useful bluetooth commands to make sure it is working with your phone (or other device) :

Enable the bluetooth connection on your phone (or other device), and activate the public visibilty

Launch a bluetooth scan on your raspberry :

Code: Select all

sudo hcitool scan
You should see your phone with its bluetooth address under the form XX:XX:XX:XX:XX:XX

Try to send a bluetooth ping to your phone, where XX:XX:XX:XX:XX:XX represents your phone bluetooth address :

Code: Select all

sudo l2ping XX:XX:XX:XX:XX:XX
Try to open a connection (XX:XX:XX:XX:XX:XX represents your phone bluetooth address) :

Code: Select all

sudo hcitool cc XX:XX:XX:XX:XX:XX
4. Pair your phone and your raspberry

Activate the ISCAN service on your raspberry to make it visible from other devices :

Code: Select all

sudo hciconfig hci0 piscan
You should now see the following line on your current bluetooth configuration (sudo hciconfig -a) :

Code: Select all

UP RUNNING PSCAN ISCAN
Launch the following service to begin the pairing step (just type it as a command and press enter) :

Code: Select all

bluez-simple-agent
Launch a bluetooth scan on your phone and select your raspberry (it should appear as an available bluetooth audio device in the list). Then, you should be asked for a PIN code : choose the code you want on your phone.

A "Enter Pin :" message should appear on your raspberry asking you for the PIN code : enter the same code you just defined on your phone and press enter. If you try to connect your phone without stopping the bluez-simple-agent, you should be asked to authorize the connection (message "Authorize connection (yes/no):").

Your phone is now paired. You can stop the bluez service by pressing Ctrl+C.

Add your phone to the bluetooth trusted devices (you will not be obligated to enter the PIN code each time you want to connect your phone to your raspberry), where XX:XX:XX:XX:XX:XX represents your phone bluetooth address :

Code: Select all

bluez-test-device trusted XX:XX:XX:XX:XX:XX yes
5. Connect the bluetooth source to the default sink

Once your phone is connected, you will see it as the bluetooth source n°1 :

Code: Select all

pactl list sources short
The command result should be (XX:XX:XX:XX:XX:XX represents your phone bluetooth address) :

Code: Select all

0    alsa_output.platform-bcm2835_AUD0.0.analog-stereo.monitor    module-alsa-card.c    s16le 2ch 44100Hz    SUSPENDED
	1    bluez_source.XX_XX_XX_XX_XX_XX    module-bluetooth-device.c    s16le 2ch 44100Hz    SUSPENDED
Check the available sinks :

Code: Select all

pactl list sinks short
The command result should be :

Code: Select all

0    alsa_output.platform-bcm2835_AUD0.0.analog-stereo    module-alsa-card.c    s16le 2ch 44100Hz    SUSPENDED
Connect the source to the sink thanks to the loopback module (XX:XX:XX:XX:XX:XX represents your phone bluetooth address) :

Code: Select all

pactl load-module module-loopback source=bluez_source.XX_XX_XX_XX_XX_XX sink=alsa_output.platform-bcm2835_AUD0.0.analog-stereo
6. Change the sound settings

Change the default HDMI sound ouput for the jack output :

Code: Select all

amixer cset numid=3 1
Turn up the sink volume :

Code: Select all

	amixer set Master 100%
	pacmd set-sink-volume 0 65537
If you play a song on your phone, it should now be redirected on your raspberry jack output. You can check it by plugging an headset to your raspberry. You can also directly connect your raspberry to your audio system though an adapted jack wire (raspberry jack output connected to an input of your audio amplifier).

This system works fine but requires a connection on your raspberry each time you want to listen music : you have to manually launch the command described on step 5 to connect the bluetooth source to the default sink though the loopback module. It means you must have a screen/keyboard/mouse connected or a network connection (ssh access) : it's not much practical, and maybe less than directly connecting your phone to your audio system though a jack wire...

I found that the lastest version of pulse audio (v4.0) includes a new module called "module-bluetooth-policy" that automatically activates the loopback module (connects the source to the sink) on each bluetooth device connection. Nevertheless, the pulse-audio version installed by default on raspbian is v2.0 (the command to get the version is : pulseaudio --version) and doesn't include such a module.

I installed the lastest version on my raspberry (it can be downloaded from here : http://www.freedesktop.org/wiki/Software/PulseAudio/) and tried to get it working with the bluetooth modules but I didn't manage to have something good (I didn't see any bluetooth source when I connected my phone and met other troubles). This is a more complicated job because you have to clone the source code from git repository, to configure makefiles, to resolve dependencies (many other packages to install), to build the application (compilation) and to deploy it on the right folders (installation).

So I decided to find another solution : a regular job that looks for a bluetooth device connection and automatically launchs the loopback module.


7. Configure pulse-audio in system mode (necessary to launch pulse without being logged on the raspberry)

Activate the pulse-audio system mode and allow module loading :

Code: Select all

sudo nano /etc/default/pulseaudio
Modify the following lines :

Code: Select all

	PULSEAUDIO_SYSTEM_START=1
	DISALLOW_MODULE_LOADING=0
Add the default user "pi" to the pulse-access group :

Code: Select all

sudo adduser pi pulse-access
Modify the pulse-audio client configuration file to deactivate autospawn :

Code: Select all

sudo nano /etc/pulse/client.conf
Modify the following line :

Code: Select all

autospawn = no
Modify the pulse-audio daemon configuration file to change the default starting options :

Code: Select all

sudo nano /etc/pulse/daemon.conf
Modify the following lines :

Code: Select all

	allow-module-loading = yes
	load-default-script-file = yes
	default-script-file = /etc/pulse/default.pa
Add some bus policy for user "pulse" :

Code: Select all

sudo nano /etc/dbus-1/system.d/pulseaudio-system.conf
Add the following lines between the <busconfig> tags :

Code: Select all

<policy user="pulse">
      <allow own="org.pulseaudio.Server"/>
      <allow send_destination="org.bluez"/>
      <allow send_interface="org.bluez.Manager"/>
</policy>
8. Create a job that looks for bluetooth connections

Create a new script file that will be regularly launched to check if a new bluetooth device have been connected and automatically launch the loopback module :

Code: Select all

mkdir /home/pi/pulseAudioBluetooth

Code: Select all

nano /home/pi/pulseAudioBluetooth/checkForBluetoothDevice.sh
(path and name of the new script file)

Copy/paste the following code into the file :

Code: Select all

#!/bin/bash

#This script looks for a bluetooth audio source and launch the pulse audio loopback module if necessary

#log traces :
#date=$(date "+%Hh%Mm%Ss")
#echo "Script Exec "$date

bluetoothSource=$(pactl list sources short | grep bluez_source)

read loopbackStatus < /home/pi/pulseAudioBluetooth/bluetoothLoopbackStatus.txt

if [[ $bluetoothSource != "" ]] && [[ $loopbackStatus == "0" ]]
then
	source=${bluetoothSource:2:30}
	pactl load-module module-loopback source=$source sink=alsa_output.platform-bcm2835_AUD0.0.analog-stereo
	echo "1" > /home/pi/pulseAudioBluetooth/bluetoothLoopbackStatus.txt
	#echo "command launched"

else
	if [[ $bluetoothSource == "" ]] && [[ $loopbackStatus == "1" ]]
	then
		echo "0" > /home/pi/pulseAudioBluetooth/bluetoothLoopbackStatus.txt
		#echo "reset loopbackStatus"
	fi
fi
Save modifications and close the script

Make it executable :

Code: Select all

sudo chmod u+x /home/pi/pulseAudioBluetooth/checkForBluetoothDevice.sh
Create a new text file to save the loopback status (file used by the script) :

Code: Select all

echo 0 > /home/pi/pulseAudioBluetooth/bluetoothLoopbackStatus.txt
(0 means that loopback module is not running, 1 means that it's running)


9. Planify a regular launch of the script

To do this, linux has an interessant service called cron that enable to planify scripts launching.

Open the cron configuration :

Code: Select all

crontab -e
Add the following lines at the end of the configuration file to launch every minute the script and to redirect standard output and errors in a text file named cron.log (you can change the files paths if necessary) :

Code: Select all

	# automatically load loopback for new bluetooth devices (check every minute)
	* * * * * /home/pi/pulseAudioBluetooth/checkForBluetoothDevice.sh  >> /home/pi/pulseAudioBluetooth/cron.log 2>&1
Save the file and exit your text editor

Reboot your raspberry :

Code: Select all

sudo reboot
At this point, your raspberry is able to automatically detect a bluetooth source and to launch the audio streaming (the source has to be paired with your raspberry - refer to step 4 if you want to add a new source). The sound will not be immediately played as soon as you connect your bluetooth source : in the worst case, you will have to wait for 1 minute (maximum time between 2 detections).

If no sound is played after more than 1 minute, you probably have a problem : check the cron.log file (/home/pi/pulseAudioBluetooth/cron.log by default) to see if something is written in it (redirection of errors).

You can now stream music from your bluetooth device without connecting your raspberry to the network.
If you want to deactivate the automatic detection, juste delete the lines you added in the cron configuration file and reboot.


Enjoy your favorite music !

I hope I'm clear in my explanations and it will be useful to some people. Don't hesitate to give your feedbacks about this tutorial !

I would like to thanks people who spent some time to share their experience about audio streaming and more particularly the authors of these articles :

- http://kmonkey711.blogspot.fr/2012/12/a ... ry-pi.html
- https://wiki.archlinux.org/index.php/PulseAudio

Some others articles that can be interesting :

- http://doc.ubuntu-fr.org/pulseaudio
- http://colin.guthr.ie/2010/09/compiling ... -from-git/

texy
Forum Moderator
Forum Moderator
Posts: 4991
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Bluetooth audio streaming

Thu Feb 06, 2014 9:18 pm

Hi and welcome to the forum ;)
Thanks for sharing and posting on the forum. Plenty of these tutorials on the net, but it's nice to see it in completion on the pi forums.
Now what I'd like to see (as previously mentioned on similar posts here ) is a way of the pi capturing the id3 tag info that must be sent from the serving device......
Now IF you could do that...

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

User avatar
Douglas6
Posts: 4013
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Bluetooth audio streaming

Sun Feb 09, 2014 12:34 am

B.ramus, you might want to look into a more automatic (and quicker) method of doing the pactl loopback. There are a couple of ways to do this:
1. Use a udev rule as described in this instructable
2. Use dbus with a python script such as one that can be found here

didi90
Posts: 2
Joined: Tue Apr 22, 2014 6:40 pm

Re: Bluetooth audio streaming

Tue Apr 22, 2014 6:45 pm

hello & thank you very much for your instruction. It works very well, but only if I connect the source manually to the sink.
When I reboot and check the cron.log file, it always says: /home/pi/pulseAudioBluetooth/checkForBluetoothDevice.sh : not found

Do you have an idea what could be wrong? I checked everything and I don't know what to do.

Thank you very much

David

dr-guzman
Posts: 5
Joined: Tue Sep 17, 2013 3:59 pm
Location: Valhalla

Re: Bluetooth audio streaming

Wed Apr 23, 2014 10:39 am

Can we use it to stream video?

b.ramus
Posts: 3
Joined: Thu Feb 06, 2014 6:41 pm

Re: Bluetooth audio streaming

Mon Jun 02, 2014 5:47 pm

Sorry for answer time, I've not been on this forum for sereval months...

@texy : I don't know if Id3 tags are available using this streaming method, it would requires to look at bluez/pulseaudio code. I think they are not easily available...

@Douglas6 : Thanks for your feedback, I agree that it would be much cleaner using udev detection or capturing dbus messages. I haven't time enough to developp it for the moment but I will look at these solutions later.

@didi90 : Are you sure that the script is located at path "/home/pi/pulseAudioBluetooth/checkForBluetoothDevice.sh" ? If you created the script somewhere else, you have to change the default path in crontab. You can try to launch it manually by running "./home/pi/pulseAudioBluetooth/checkForBluetoothDevice.sh" : if you get a not-found error, your script is not located there and you have to update the path with the right one.

@dr-guzman : No, bluez and pulse audio are only intented to stream audio content, but you have other solutions to stream video content. I think there are a lot of applications that use raspberry camera module to get live video, and it is also possible using basic usb webcams. I don't know if you can easily do it using bluetooth, most of applications use conventional network connections (TCP / UDP sockets). You can also use frameworks such as JMF if you want to make your own video streaming application.

amarsaudon
Posts: 3
Joined: Tue Apr 01, 2014 5:55 pm

Re: Bluetooth audio streaming

Tue Jun 03, 2014 6:43 pm

Hey there! Thanks for the incredibly comprehensive guide; it worked first try for me! My only question is, as configured it outputs Bluetooth audio to the integrated 3.5mm audio jack. I have a USB DAC, and would love if pulse audio could output to that!

My Pi is configured with pianobar per this guide: https://learn.adafruit.com/downloads/pd ... -radio.pdf (including the LCD)
USB DAC is a CM108 chipset, configured per this: https://learn.adafruit.com/usb-audio-ca ... spberry-pi

Thanks for any help anyone can provide on this!
-Alex

**EDIT Because I'm pretty sure this is useful**
Here is the output from my "pactl list sinks short"
pi@PandoraPi ~ $ pactl list sinks short
0 alsa_output.usb-0d8c_C-Media_USB_Audio_Device-00-Device.analog-stereo module-alsa-card.c s16le 2ch 48000Hz SUSPENDED
1 alsa_output.platform-bcm2835_AUD0.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz

b.ramus
Posts: 3
Joined: Thu Feb 06, 2014 6:41 pm

Re: Bluetooth audio streaming

Wed Jun 04, 2014 6:39 pm

Hi,

Thanks for your feedback and for sharing your own project !

Your usb device seems to be detected as an available audio sink : it's a good point for you !
Have you already tried to launch the following command where XX_XX_XX_XX_XX_XX is your bluetooth device address :

Code: Select all

pactl load-module module-loopback source=bluez_source.XX_XX_XX_XX_XX_XX sink=alsa_output.usb-0d8c_C-Media_USB_Audio_Device-00-Device.analog-stereo
What is the output of this command ? Do you meet a particular error ?

Grantysid
Posts: 3
Joined: Sun Jan 05, 2014 9:15 am

Re: Bluetooth audio streaming

Mon Jun 16, 2014 10:14 am

Howdy,

Top tutorial, took me a couple of goes to get it sorted but works well now!!

Traps to fall into :

First, use the version of Raspbian listed at the start of the tutorial, the later versions will give errors when you try to use the "pactl" commands and hang your Pi. Google to get the right one and it will work.

Second, in the initial Pi setup, enable SSH and then use Putty on your PC to copy and paste the commands from the tutorial into the SSH session. This avoids the typo's of doing it yourself, especially that shell script which needs to be formatted perfectly for it to work.

You do need an external amp to get acceptable volume, but it pumps out nicely out of my stereo, via my mobile phone from the couch. Audio quality is just fine, given how it works.

Next step is to try it out in the car, the car stereo has a aux 3.5mm audio input but it's a pain to connect it up with the phone all the time when you are getting in and out. Much easier with a wireless connection, will see how well it auto connects, but it's a great start.

Thanks for the tutorial, great work!!

Cheers.

texy
Forum Moderator
Forum Moderator
Posts: 4991
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Bluetooth audio streaming

Mon Jun 16, 2014 11:58 am

First, use the version of Raspbian listed at the start of the tutorial, the later versions will give errors when you try to use the "pactl" commands and hang your Pi. Google to get the right one and it will work.
Rather suggesting google, are you able to post the specific method?
Thanks
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

Predatorian
Posts: 1
Joined: Sun Jul 06, 2014 11:25 pm

Re: Bluetooth audio streaming

Sun Jul 06, 2014 11:26 pm

I'm surprised that there isn't some lightweight distro already prepackaged for this. Guess I got myself a mission.

Gabino75
Posts: 16
Joined: Sun Jul 20, 2014 6:17 pm

Re: Bluetooth audio streaming

Tue Jul 22, 2014 4:01 pm

cron.log is giving me

Code: Select all

pa_context_connect () failed: Connection refused
Connection failure: Connection refused
Any ideas on what could be causing this?

User avatar
Douglas6
Posts: 4013
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Bluetooth audio streaming

Wed Jul 23, 2014 3:49 pm

Try adding 'pi' (or whatever user the cron job was created with) to the pulse-access group.

Code: Select all

useradd -G pulse-access pi 
I believe this is needed for the pactl command. Alternately, change the cron job thusly:

Code: Select all

sudo -u pulse pactl load-module module-loopback source=$source sink=alsa_output.platform-bcm2835_AUD0.0.analog-stereo

evanhdon
Posts: 4
Joined: Mon Aug 25, 2014 5:12 am

Re: Bluetooth audio streaming

Tue Aug 26, 2014 4:35 am

With the updated software (Raspbian 2014-06-20), the following code:

Code: Select all

amixer cset numid=3 1
should be changed to

Code: Select all

amixer -c 0 cset numid=3 1
This will actually change the output location, instead of turning the Master volume all the way down like the former.

Evan

DFog
Posts: 3
Joined: Fri Aug 24, 2012 12:12 am

Re: Bluetooth audio streaming

Fri Sep 05, 2014 1:52 am

Alright. So, the moment I input the command at the end of step 5 I get clean audio streamed from my phone. However, after about 15 second or so the sound cuts out and no longer pays despite my phone streaming to the pi. I went through with the rest of the steps to see if it would resolve itself, but it did not. Any ideas folks? Thank you.

Volectorus
Posts: 1
Joined: Wed Oct 01, 2014 2:46 am

Re: Bluetooth audio streaming

Fri Oct 03, 2014 2:04 am

Hi,
I Followed your directions exactly with the exception of changing the audio output to the audio jack. Everything worked flawlessly. With that said. i went back to change output from HDMI. now nothing. any ideas?

Anthar
Posts: 5
Joined: Mon Nov 03, 2014 2:35 pm

Re: Bluetooth audio streaming

Mon Nov 03, 2014 2:43 pm

hello,

I wonder if it's possible to retrieve the song name and artist sent by the smartphone to display this information on a small LCD screen attached to the raspberry pi.

Thank you for your answer.

texy
Forum Moderator
Forum Moderator
Posts: 4991
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Bluetooth audio streaming

Mon Nov 03, 2014 2:46 pm

Anthar wrote:hello,

I wonder if it's possible to retrieve the song name and artist sent by the smartphone to display this information on a small LCD screen attached to the raspberry pi.

Thank you for your answer.
Getting ID3 tags has already been asked - http://www.raspberrypi.org/forums/viewt ... 28#p501453

Let us know how to do it when you find out..............

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

User avatar
Douglas6
Posts: 4013
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Bluetooth audio streaming

Mon Nov 03, 2014 3:16 pm

I've spent a bit of time on this, and I'm pretty sure it's not possible with Bluez 4.99, as it is in the Raspian Wheezy repos. Track meta data information was added in the AVRCP 1.3 spec, which is supported, but not fully, in Bluez 4.99, as far as I can tell. By the way, AVRCP metadata is NOT an ID3 tag, it's part of the Bluetooth spec, and includes artist, title and genre, but not cover art.

On the other hand, it IS possible on the Raspberry Pi running Wheezy, if you want to build and install Bluez 5.23 and PulseAudio 5.0 from source code. I have working Python code to display track and artist on a character LCD display. It can also send pause, play, mute and skip commands to the mobile device (I've had no success with volume control). Installing Bluez 5 and PA 5 is a bit of work (mostly waiting), but I posted a detailed guide here.

If there's interest, I'll post up the Python code (currently written for the Adafruit LCD plate with buttons). I'd consider it alpha at this point, but it works well with an Android 4.4 phone running Google Play Music or Pandora. Not tested on iPhones.

Anthar
Posts: 5
Joined: Mon Nov 03, 2014 2:35 pm

Re: Bluetooth audio streaming

Mon Nov 03, 2014 3:58 pm

Hi Douglas6.
If I understand correctly, it is possible to retrieve the name of the artist and songs with bluez V5 and pulse audio V5.
I want to see your code to retrieve that information and display it.

Thank you!

User avatar
Douglas6
Posts: 4013
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Bluetooth audio streaming

Tue Nov 04, 2014 4:37 am

You understand correctly. I've posted some Python code over on my BlueZ5/PA5 thread here.

chornig
Posts: 1
Joined: Mon Nov 17, 2014 9:41 pm

Re: Bluetooth audio streaming

Mon Nov 17, 2014 9:45 pm

Hey there,

I don't get the same output as you do when I want to pair the devices.
When I start bluez-simple-agent I get only a yes/no question and I do not have the possibility to enter the passcode hence I cannot connect.

What can I do?

Thanks!

sda0786
Posts: 1
Joined: Mon Dec 01, 2014 2:39 pm

Re: Bluetooth audio streaming

Mon Dec 01, 2014 2:56 pm

Douglas6 wrote:B.ramus, you might want to look into a more automatic (and quicker) method of doing the pactl loopback. There are a couple of ways to do this:
1. Use a udev rule as described in this instructable
2. Use dbus with a python script such as one that can be found here

This guide worked almost perfect for me! I still have a huge problem. I have lag between the start of the song and the actual music. This is not a big deal while I'm listening just music but is very bad when I want to hear the audio from a video.
Audio and video will not be sync!

Any Idea?

User avatar
Douglas6
Posts: 4013
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Bluetooth audio streaming

Mon Dec 01, 2014 6:38 pm

I'm afraid that's just the nature of Bluetooth. I get about a half second delay or more, so I always use wired speakers for video. Some video players permit a configurable delay in the video, I think, but I can't help there.

a_bet
Posts: 8
Joined: Tue Dec 09, 2014 10:30 pm

Re: Bluetooth audio streaming

Wed Dec 17, 2014 11:47 pm

Hi, thanks for the great guide.
I'm trying to follow it on the 9-9-2014 raspian Wheezy and I'm stuck at the bluethoot pairing.
I can scan for devices using

Code: Select all

sudo hcitool scan
, I can even see my phone, but if I run

Code: Select all

sudo l2ping <address>
all i get from the pi is

Code: Select all

Cannot connect: invalid exchange

So I searched a bit and I found out that a possible solution could be

Code: Select all

If l2ping responds with "invalid exchange" it is possible that your target device does not support encryption. For that change the auth and encrypt lines in hcid.conf to:
auth disable;
encrypt disable;
(http://www.nslu2-linux.org/wiki/Periphe ... othAdapter)
Well, the fun fuct is that on mi Pi the hcid.conf does not exist.

Might this be because I'm running a newer realese of raspian?? Anyone with the same problem?
Any help would be really appreciated!

Return to “Graphics, sound and multimedia”

Who is online

Users browsing this forum: No registered users and 13 guests