pi-kster
Posts: 1
Joined: Sat Mar 03, 2018 12:29 pm

Bluetooth audio not working in Kodi

Sat Mar 03, 2018 12:38 pm

Hello, this is my first post on this forum. :D

In Raspbian I can succesfully pair my Logitech Bluetooth adapter and play music over my Speakers with VLC. Unfortunately, when I enter Kodi and select: "ALSA: Default (bcm2835 ALSA bcm2835 ALSA)" as audio output, it plays music and movies through HDMI (my TV speakers). Other audio outputs are HDMI and Analog.

My problem is thus that I would like my movies and audio played through my bluetooth speakers rather than my TV speakers. I am using a Raspberry Pi 2 with compatible bluetooth adapter. Running latest, unmodified, Raspbian with Kodi 17.6.

I have searched all over the web, but am not succesfull in finding a solution :roll:

Is there someone who could help me find a fix for my bluetooth issues? :D

rcp87
Posts: 2
Joined: Tue Apr 03, 2018 8:13 am

Re: Bluetooth audio not working in Kodi

Tue Apr 03, 2018 8:21 am

Hello, I'm in the same situation. I connect a headset by bluetooth without any problems and audio is working in youtube, but not in Kodi. I tried with a solution seen in this page: https://www.raspberrypi.org/magpi/bluet ... erry-pi-3/ but with no luck... :(
I don't know why is working in raspbian without any problems, but not in Kodi, is weird. Any help would be really appreciated.
PD: Is my first post in this forum too :)

hellesangel
Posts: 5
Joined: Sat Nov 12, 2016 3:25 pm

Re: Bluetooth audio not working in Kodi

Wed Jun 06, 2018 10:03 am

Same situation here.... A plain Raspbian install, everything standard, works fine with the Anker external BT speakers, but Kodi does not recognise the device. I have done a lot of Googling and ended up with a mess of partial ideas and articles from some years back that I can only assume are out of date.

Specific questions that someone may be able to answer:
  • If Pulseaudio is installed on top of Raspbian can Kodi & Bluetooth be made to work nicely together?
  • If so then can anyone show how to do this?
  • If the Pi is reinstalled with OpenELEC will it be easier to get Kodi & Bluetooth working?
Thanks in advance for any help.

Rascas
Posts: 568
Joined: Tue Mar 11, 2014 6:18 pm
Location: Porto, Portugal
Contact: Website

Re: Bluetooth audio not working in Kodi

Wed Jun 06, 2018 11:55 am

I think you need to edit the alsa config manually and define the device you want as default. I have tried this some time ago and it worked but it was only for testing. Search for alsa.conf and/or asoundrc.

hellesangel
Posts: 5
Joined: Sat Nov 12, 2016 3:25 pm

Re: Bluetooth audio not working in Kodi

Wed Jun 06, 2018 2:11 pm

Great, thanks for the hint. I take it that there is no need for Pulseaudio any more.

I'll try a bit more hacking and see if I can get this going.

Rascas
Posts: 568
Joined: Tue Mar 11, 2014 6:18 pm
Location: Porto, Portugal
Contact: Website

Re: Bluetooth audio not working in Kodi

Wed Jun 06, 2018 2:21 pm

Installing Pulseaudio should work also, it worked in Jessie, but since now Alsa (with bluealsa, etc) is now the default in Stretch, I never tested it. PulseAudio can add some latency, specially in low cost SBCs like the Raspberry Pi if you are pushing it, so I recommend that you try with Alsa first.

DarkElvenAngel
Posts: 196
Joined: Tue Mar 20, 2018 9:53 pm

Re: Bluetooth audio not working in Kodi

Wed Jun 06, 2018 3:01 pm

Hello,

I'm also attempting to get kodi from a stock image to stream sound via Bluetooth (in my case to a car head unit) I've followed this guild to get the latest bluez
https://www.sigmdel.ca/michel/ha/rpi/bl ... 02_en.html

Also I've created a .asoundrc file

Code: Select all

defaults.bluealsa.interface "hci0"
defaults.bluealsa.device "xx:xx:xx:xx:xx:xx"
defaults.bluealsa.profile "a2dp"
defaults.bluealsa.delay 10000
everything is paired and trusted yet I can't seem to get play back even with omxplayer
I do get static when playing an mp3 with aplay (I know it cannot play mp3, but it proved I could get some sound through)

Have I missed anything? If nothing else I hope some of this information is helpful to one of you.

hellesangel
Posts: 5
Joined: Sat Nov 12, 2016 3:25 pm

Re: Bluetooth audio not working in Kodi

Fri Jun 08, 2018 8:49 am

The stock Raspbian should be able to pair Bluetooth devices and get an audio connection established that gets your audio out to the speaker, which was the state I got to in my post above. Then I discovered Kodi is special... So let's take your problem in stages.

Bluetooth has two stages to getting devices operational - first pairing, and then connection. Can you verify that you have a Bluetooth connection to your device - from the GUI right clicking the 'audio' icon should allow you to connect the BT device. That is step 3 in the link you used from the CLI. With the device paired and connected you should be able to get sound out of your browser, for example YouTube.

Once the BT device is both paired and connected then it is a matter of getting a Linux system to build an audio route from application to device.... This is where my knowledge runs a bit thin. It seems applications, like Kodi, do not necessarily use the Linux system defined output device but can choose their own. And it is confusing....

evilblade
Posts: 2
Joined: Fri Jun 08, 2018 12:38 pm

Re: Bluetooth audio not working in Kodi

Fri Jun 08, 2018 12:44 pm

Having the exact same problem here. Audio via bluetooth works everywhere _except_ Kodi :(
Does anyone have a solution for this issue yet?..

DarkElvenAngel
Posts: 196
Joined: Tue Mar 20, 2018 9:53 pm

Re: Bluetooth audio not working in Kodi

Fri Jun 08, 2018 3:24 pm

I don't always have access to the car with bluetooth so I plugged in a usb speaker. This works with kodi it comes up in the list of available output devices.

So this got me thinking doesn't alsabluez create a device like my USB speaker does. Is it possible to create a device link to a Bluetooth device when it's paired that Kodi will use?

I'll test this out next time I'm able.

DarkElvenAngel
Posts: 196
Joined: Tue Mar 20, 2018 9:53 pm

Re: Bluetooth audio not working in Kodi

Fri Jun 08, 2018 4:15 pm

hellesangel wrote:
Fri Jun 08, 2018 8:49 am
The stock Raspbian should be able to pair Bluetooth devices and get an audio connection established that gets your audio out to the speaker, which was the state I got to in my post above. Then I discovered Kodi is special... So let's take your problem in stages.

Bluetooth has two stages to getting devices operational - first pairing, and then connection. Can you verify that you have a Bluetooth connection to your device - from the GUI right clicking the 'audio' icon should allow you to connect the BT device. That is step 3 in the link you used from the CLI. With the device paired and connected you should be able to get sound out of your browser, for example YouTube.

Once the BT device is both paired and connected then it is a matter of getting a Linux system to build an audio route from application to device.... This is where my knowledge runs a bit thin. It seems applications, like Kodi, do not necessarily use the Linux system defined output device but can choose their own. And it is confusing....
Sorry I missed this, I assume you're referring to the pixel desktop, I'm working strictly from the command line. My project has no use for a desktop. I've been able to get omxplayer to play directly to my USB speaker not in my original setup,that can be found here viewtopic.php?f=28&t=214920 I had some issues with my display as well as Bluetooth. It's just a matter or having access and time with the car to test my theory for Bluetooth.

The Pi is able to reconnect with the car on boot so as far as that goes I have no issues it's just streaming audio over. That is due to my lack of time and my unfamiliarity with how to use the Alsa stack properly.

DarkElvenAngel
Posts: 196
Joined: Tue Mar 20, 2018 9:53 pm

Re: Bluetooth audio not working in Kodi

Fri Jun 08, 2018 9:09 pm

I GOT IT

I have Bluetooth sound in Kodi working.

This is how to do it

Make sure your speaker is paired and connected

You need to make a .asoundrc file in your home directory

Code: Select all

defaults.bluealsa.interface "hci0"
defaults.bluealsa.device "xx:xx:xx:xx:xx:xx"
defaults.bluealsa.profile "a2dp"
defaults.bluealsa.delay 10000
where xx:xx:xx:xx:xx:xx is the mac address of your Bluetooth speaker.

Then open ./kodi/userdata/guisettings.xml

Code: Select all

<audiooutput>
      ...
    <audiodevice>ALSA:bluealsa</audiodevice>
      ...
change the audiooutput to ALSA:bluealsa

This change will be overwritten if you open the settings so be careful.

Also it seems to help if you set the audio to ALSA default beforehand if you are not getting results.

I'll look deeper into this but I was excited for working results and thought I would share the success and how to recreate!

Edit: I should mention if you're having trouble I followed this guide https://www.sigmdel.ca/michel/ha/rpi/bl ... 02_en.html to update the Bluetooth tools to the latest version. If you're using a different version that myself your mileage may vary.

evilblade
Posts: 2
Joined: Fri Jun 08, 2018 12:38 pm

Re: Bluetooth audio not working in Kodi

Sat Jun 09, 2018 6:19 am

The thing is.. I already had .asoundrc in my ~ and it's:

Code: Select all

pcm.!default {
	type plug
	slave.pcm {
		type bluealsa
		device "4C:21:D0:A0:A0:EE"
		profile "a2dp"
	}
}

ctl.!default {
	type bluealsa
}
And it's overwritten to this state after reboot if I edit it...

Tried to change guisettings.xml to set audiodevice to ALSA:bluealsa ...still no sound in BT-headset :(

DarkElvenAngel
Posts: 196
Joined: Tue Mar 20, 2018 9:53 pm

Re: Bluetooth audio not working in Kodi

Sat Jun 09, 2018 11:58 am

evilblade wrote:
Sat Jun 09, 2018 6:19 am
The thing is.. I already had .asoundrc in my ~ and it's:

Code: Select all

pcm.!default {
	type plug
	slave.pcm {
		type bluealsa
		device "4C:21:D0:A0:A0:EE"
		profile "a2dp"
	}
}

ctl.!default {
	type bluealsa
}
And it's overwritten to this state after reboot if I edit it...

Tried to change guisettings.xml to set audiodevice to ALSA:bluealsa ...still no sound in BT-headset :(
I'm using a rasbian lite image are you using a full one?

Did you try following the guild I did?

I feel that the if another program is overwriting this file you may need a script to work around. I'm working on one for myself.

One thing to try in Kodi switch your sound output the "Alsa default "

In the guisetting.xml the sounddevice should say ALSA:@. There may be other settings that need to change. I can post a complete copy later today

postiejohn
Posts: 15
Joined: Sun Oct 29, 2017 10:11 am

Re: Bluetooth audio not working in Kodi

Tue Jun 19, 2018 8:34 am

EVILBLADE your so close to getting it working

asoundrc is created when you connect the the bluetooth device via the desktop and is exactly what you have posted.

now all you have to do is edit guisettings.xml and replace the audiodevice as

<audiodevice>ALSA:default</audiodevice>

then start kodi

do not go into settings as this will overwrite guisettings.xml

DarkElvenAngel
Posts: 196
Joined: Tue Mar 20, 2018 9:53 pm

Re: Bluetooth audio not working in Kodi

Tue Jun 19, 2018 11:59 am

postiejohn wrote:
Tue Jun 19, 2018 8:34 am
EVILBLADE your so close to getting it working

asoundrc is created when you connect the the bluetooth device via the desktop and is exactly what you have posted.

now all you have to do is edit guisettings.xml and replace the audiodevice as

<audiodevice>ALSA:default</audiodevice>

then start kodi

do not go into settings as this will overwrite guisettings.xml
postiejohn, a few questions how do you launch kodi from the desktop? does this work for you? I'm asking because I'm not using the desktop and I've set kodi in the audio settings to default and that didn't work. it sets this line as

Code: Select all

<audiodevice>ALSA:@</audiodevice>
if I set it to ALSA:bluealsa it works.

postiejohn
Posts: 15
Joined: Sun Oct 29, 2017 10:11 am

Re: Bluetooth audio not working in Kodi

Tue Jun 19, 2018 12:23 pm

I use the full version of Raspbian Stretch and connect to bluetooth from the desktop. I make sure I can get the headphones working first, edit the guisettings, then launch kodi from the desktop menu

I actually got the audio device setting from playing around with vlc which gives an error if your bluetooth is not connected and tells you the device it is looking for. It was obviously a quick fix by someone as vlc didn't work in previous versions of the stretch image.

I failed to get it working in raspbianlite,. but I see no reason why the asoundrc file produced by the desktop should not work in the lite version provided you have connected to the BT device.

Edit: Just tried ALSA:bluealsa and it didn't work and if I then goto settings in kodi and quit it has changed my guisettings to [email protected]

postiejohn
Posts: 15
Joined: Sun Oct 29, 2017 10:11 am

Re: Bluetooth audio not working in Kodi

Tue Jun 19, 2018 2:59 pm

I can confirm DarkElevenAngel's method works when not in the desktop (to exit use CTRL-ALT-F2 and login)
and mine works from the desktop.
they are mutually exclusive!

DarkElvenAngel wrote:
Fri Jun 08, 2018 9:09 pm


You need to make a .asoundrc file in your home directory

Code: Select all

defaults.bluealsa.interface "hci0"
defaults.bluealsa.device "xx:xx:xx:xx:xx:xx"
defaults.bluealsa.profile "a2dp"
defaults.bluealsa.delay 10000
where xx:xx:xx:xx:xx:xx is the mac address of your Bluetooth speaker.

Then open ./kodi/userdata/guisettings.xml

Code: Select all

<audiooutput>
      ...
    <audiodevice>ALSA:bluealsa</audiodevice>
      ...

Rascas
Posts: 568
Joined: Tue Mar 11, 2014 6:18 pm
Location: Porto, Portugal
Contact: Website

Re: Bluetooth audio not working in Kodi

Tue Jun 19, 2018 3:30 pm

For what I read, the main problem with Kodi and bluetooth devices through ALSA, is that, when you configure the device, it is loaded like a plugin and not a real device, like an USB sound card, for example. Kodi seems to not support ALSA "plugins" (don't know if it is the correct term), and so, it does not appear in the Kodi sound settings.
Don't edit guisettings.xml, that file is overwritten by Kodi, add a new line (or create the file if it doesn't exist) to advancedsettings.xml. Check the Kodi wiki for how to do it. It will probably be changed again if you go to the audio settings in Kodi, but it will work again if you restart Kod at least.

postiejohn
Posts: 15
Joined: Sun Oct 29, 2017 10:11 am

Re: Bluetooth audio not working in Kodi

Tue Jun 19, 2018 4:34 pm

Rascas wrote:
Tue Jun 19, 2018 3:30 pm
For what I read, the main problem with Kodi and bluetooth devices through ALSA, is that, when you configure the device, it is loaded like a plugin and not a real device, like an USB sound card, for example. Kodi seems to not support ALSA "plugins" (don't know if it is the correct term), and so, it does not appear in the Kodi sound settings.
Don't edit guisettings.xml, that file is overwritten by Kodi, add a new line (or create the file if it doesn't exist) to advancedsettings.xml. Check the Kodi wiki for how to do it. It will probably be changed again if you go to the audio settings in Kodi, but it will work again if you restart Kod at least.
OK for good form using advancedsettings (and I hate doing this as I'm an old coder who likes using gotos from loops)

To get Bluetooth working on desktop /home/pi/.kodi/userdata/advancedsettings.xml should contain

Code: Select all

<advancedsettings>
<audiooutput>
<audiodevice>ALSA:default</audiodevice>
</audiooutput>

</advancedsettings>
To get Bluetooth working without desktop /home/pi/.kodi/userdata/advancedsettings.xml should contain

Code: Select all

<advancedsettings>
<audiooutput>
<audiodevice>ALSA:bluealsa</audiodevice>
</audiooutput>

</advancedsettings>

DarkElvenAngel
Posts: 196
Joined: Tue Mar 20, 2018 9:53 pm

Re: Bluetooth audio not working in Kodi

Tue Jun 19, 2018 10:42 pm

postiejohn wrote:
Tue Jun 19, 2018 2:59 pm
I can confirm DarkElevenAngel's method works when not in the desktop (to exit use CTRL-ALT-F2 and login)
and mine works from the desktop.
they are mutually exclusive!
Thanks for confirming

I'm going to try and write a plugin to look after this Bluetooth audio for my sake, I'm thinking this is the only way get the proper config with out manual edit.

I can tell you that setting up the sound like that in the advancedsetting will not work if you open the settings in kodi the driver in advancesetting isn't honoured and it will play sound through HDMI for example and not Bluetooth and you have to quit and reset the settings again.

I looked into adding more sound devices to the list but came up empty.

my other thought was to go with my settings files hosted on a ram disk and copy them from a read-only file on boot. this would reset them without me having to do it manually and also if my daughter messes up the settings a reboot fixes all.

Rascas
Posts: 568
Joined: Tue Mar 11, 2014 6:18 pm
Location: Porto, Portugal
Contact: Website

Re: Bluetooth audio not working in Kodi

Tue Jun 19, 2018 11:37 pm

DarkElvenAngel wrote:
Tue Jun 19, 2018 10:42 pm
postiejohn wrote:
Tue Jun 19, 2018 2:59 pm
I can confirm DarkElevenAngel's method works when not in the desktop (to exit use CTRL-ALT-F2 and login)
and mine works from the desktop.
they are mutually exclusive!
Thanks for confirming

I'm going to try and write a plugin to look after this Bluetooth audio for my sake, I'm thinking this is the only way get the proper config with out manual edit.

I can tell you that setting up the sound like that in the advancedsetting will not work if you open the settings in kodi the driver in advancesetting isn't honoured and it will play sound through HDMI for example and not Bluetooth and you have to quit and reset the settings again.

I looked into adding more sound devices to the list but came up empty.

my other thought was to go with my settings files hosted on a ram disk and copy them from a read-only file on boot. this would reset them without me having to do it manually and also if my daughter messes up the settings a reboot fixes all.
Atleast for me it works in advancedsettings.xml. Probably, you didn't set it right, like the device name or something.

DarkElvenAngel
Posts: 196
Joined: Tue Mar 20, 2018 9:53 pm

Re: Bluetooth audio not working in Kodi

Wed Jun 20, 2018 12:35 am

Just to confirm did you open the setting in Kodi and select something else as your sound device? I copied the whole audio section with nano <ctrl> + <k> and then pasted <ctrl> + <u> very low chance of a typo.

I wanted to see what would happen, If I chose HDMI audio and then I got no Bluetooth sound and had to rewrite the config file. This was with the advanced settings in place.

I'm interested if you can replicate that? because writing the advanced config file is much easier than writing scripts to look after these things.

Rascas
Posts: 568
Joined: Tue Mar 11, 2014 6:18 pm
Location: Porto, Portugal
Contact: Website

Re: Bluetooth audio not working in Kodi

Wed Jun 20, 2018 1:19 am

DarkElvenAngel wrote:
Wed Jun 20, 2018 12:35 am
Just to confirm did you open the setting in Kodi and select something else as your sound device? I copied the whole audio section with nano <ctrl> + <k> and then pasted <ctrl> + <u> very low chance of a typo.

I wanted to see what would happen, If I chose HDMI audio and then I got no Bluetooth sound and had to rewrite the config file. This was with the advanced settings in place.

I'm interested if you can replicate that? because writing the advanced config file is much easier than writing scripts to look after these things.
What happens for me is, with the device in advancedsettings.xml, if it is connected and paired, Kodi uses it, but I cannot go to the audio settings, otherwise, hdmi is selected and I cannot select the bluetooth device again. If I restart Kodi, the bluetooth device is used again.

DarkElvenAngel
Posts: 196
Joined: Tue Mar 20, 2018 9:53 pm

Re: Bluetooth audio not working in Kodi

Wed Jun 20, 2018 11:54 am

Rascas wrote:
DarkElvenAngel wrote:
Wed Jun 20, 2018 12:35 am
Just to confirm did you open the setting in Kodi and select something else as your sound device? I copied the whole audio section with nano <ctrl> + <k> and then pasted <ctrl> + <u> very low chance of a typo.

I wanted to see what would happen, If I chose HDMI audio and then I got no Bluetooth sound and had to rewrite the config file. This was with the advanced settings in place.

I'm interested if you can replicate that? because writing the advanced config file is much easier than writing scripts to look after these things.
What happens for me is, with the device in advancedsettings.xml, if it is connected and paired, Kodi uses it, but I cannot go to the audio settings, otherwise, hdmi is selected and I cannot select the bluetooth device again. If I restart Kodi, the bluetooth device is used again.
Okay I have the same issue it works until you open that audio settings even with the advancedsettings.xml. That's why I said not to rely on advancedsettings.xml. There doesn't seem to be a way to lock the audio settings, so even if you open them they won't change.

Return to “Troubleshooting”