LibreELEC Kodi as a BLuetooth audio receiver??

  • I can connected my Raspberry Pi 3B+ to bluetooth devices like a keyboard, Harmony Smart Hub remote, and my Android Smartphone. But I have not figured out how to get my smartphone to play music and have the RP3B+ receive that and send it to the speaker system I have connected to the RP3B+ via 3.5mm audio out jack.

    Is that possible and if so, how do I configure it?

  • Pulseaudio [LibreELEC.wiki][]=bluetooth#bluetooth_audio_receiving

    Missed that one in my search. I'll see if I can make it work.

    EDIT:

    Okay I used the pulseaudio link as a guide and I can set my source correctly. Now how do I get the music that is playing on my phone to play on the Kodi system. My audio output is PI:Analogue since my sound comes out the 3.5mm jack and into the AV receiver.

    pactl set-default-source bluez_source.C8_D7_B0_C1_1A_65.a2dp_source

    set the source, but there must be some other step I'm missing. In Music my only source is a directory on my NAS.

    Thanks,

    Jim A

    Edited once, last by jfabernathy (February 4, 2020 at 6:56 PM).

  • Hello everyone.

    Same as OP, I have RPi 3B+ with LibreELEC, and I want to use it as bluetooth audio sink.

    I have another problem - I can't add bluetooth as source.

    When I type

    Code
    pactl list short sources

    no BT source available, and only result is

    Quote

    1 alsa_output.0.iec958-stereo.monitor module-alsa-card.c s16le 2ch 44100Hz SUSPENDED

    Listing modules with

    Code
    pactl list short modules | grep blue

    shows that exist

    Quote

    10 module-bluetooth-policy

    11 module-bluetooth-discover

    12 module-bluez5-discover

    but loading any of them results to error message

    Quote

    Failure: Module initialization failed

    So, I'm kind of stuck now. Can you advise something?

    Thank you.

  • Hello,

    I have a RPI4 using LE 9.2.5.

    Here is what I did, perhaps this will also work for you. If others have a more efficient way of doing this, please update this thread.

    1. Modify /flash/config.txt with the following line:
      dtparam=audio=on
    2. Go to LibreElec settings, services, and ensure Bluetooth is on. :)
    3. Modify or create the file /storage/.config/autostart.sh with the following line:
      pactl load-module module-udev-detect
    4. Create a file called /storage/.kodi/userdata/bluetooth.py with the following lines:
      • NOTE Indentation of the if statement is important
      import os, subprocess, xbmc
      #Perform the below shell command. This assigns the bluetooth device as a default source for Kodi
      os.system("pactl set-default-source `pactl list short sources | grep -i blue | awk {'print $2 '}`")
      #Assign the output of the shell command to BT_NAME (Bluetooth Name)
      BT_NAME = subprocess.check_output("pactl list sources | grep -i bluetooth.protocol -A 1 | awk 'FNR==2{print $3}'", shell=True)
      #If the variable is not empty, create a KODI dialog showing the name of the bluetooth device.
      if BT_NAME:
      xbmc.executebuiltin("Notification(Bluetooth,Activated %s,3000)" % BT_NAME) #Be sure this line is indented
      os.system("pactl unload-module module-loopback")
      os.system("pactl load-module module-loopback latency_msec=1000")
      #If the variable is empty, creatae a KODI dialog showing no bluetooth device found.else:
      xbmc.executebuiltin("Notification(Bluetooth,No Blutooth Device Found,3000)") #Be sure this line is indented
    1. Modify or create the file /storage/.kodi/userdata/keymaps/gen.xml with the following lines:
      • NOTE Modify Key Id as appropriate. Recommend using the Key Editor Addon to find the key id.
      <keymap>
      <global>
      <keyboard>
      <key id="254">RunScript(special://masterprofile/bluetooth.py)
      </key>
      </keyboard>
      </global>
      </keymap>
    2. Reboot

    After you complete the items above and reboot, perform the following whenever you want a Bluetooth device to stream audio to Kodi.

    1.) Use the LibreElec settings page to pair the bluetooth device (e.g. smartphone, etc...)

    2.) On your remote, press the key that you assigned in step 5.

    3.) On Kodi, you should see a notification dialog showing the name of the bluetooth device you paired. Kodi has now set this as the default source.

    4.) Start playing media on your bluetooth device. You should hear it being output from Kodi.

    *NOTE* The steps below assume audio over HDMI. This is what I use and works fine for me.

    If you are using the analog output for your audio, I have read that others need to set amixer to output to the analog port.

    "amixer cset numid=3,1"

    *EDIT* I've noticed that sometimes the first time you try to play something, the audio is very slow. If you stop playing, then simply start playing again then the audio is fine. By putting in the these extra lines in bluetooth.py this problem seems to go away. Unsure why exactly:

    os.system("pactl unload-module module-loopback")
    os.system("pactl load-module module-loopback latency_msec=1000")

    If anyone smarter than me could chime in, it would be appreciated.

  • OK, so I'm a LibreELEC Kodi noob. I'm running a Rpi3B+ with a HifiBerry Amp2 connected to a vintage stereo. I can stream stations via my Kodi, but I'd like to use my phone's bluetooth connection to stream music from my phone, through Kodi, into the stereo. I've researched the forums, and I'm never quite sure I've found a direct fix. I have enabled the Bluetooth on the Kodi, and it pairs with my phone, but how to hear the audio?

    Help appreciated.

  • Hi, did you get it running on le 10?

  • Just tested incompetent-nerd's post on LE 10.0.0.1 with RPI4, works like a charm for me!

    Just added on line in /storage/.config/autostart.sh, so that audio comes from hdmi instead of pulseaudio default stereo output:

    Code
    pactl load-module module-udev-detect
    pactl set-default-sink alsa_output.0.hdmi-stereo

    And i used os.popen().read() instead of subprocess.check_output() to get a unicode string instead of binary array in

    /storage/.kodi/userdata/bluetooth.py:

  • I use LE 10 and HDMI and I had a problem, the sound was not send to the HDMI. My solution was to move

    Code
    pactl set-default-sink alsa_output.0.hdmi-stereo

    from the autostart to the bluetooth.py as

    Edited 6 times, last by black-rollex (May 2, 2022 at 6:24 PM).

  • I setted up the bluetooth connection in the described way but my sound is super distorted and cuts off, especially in the beginning after connecting. Anybody with the same problem or know a solution?

    Edited once, last by jo87casi (May 19, 2022 at 1:36 AM).

  • I setted up the bluetooth connection in the described way but my sound is super distorted and cuts off, especially in the beginning after connecting. Anybody with the same problem or know a solution?

    Try this:

    First connect your bluetooth source from LE settings addon..then run this..

    Bash
    #!/bin/sh
    systemctl stop kodi
    pactl load-module module-udev-detect 2>/dev/null
    sink=`pactl list short sinks | grep 'alsa' | awk '{print $2}' | grep 'hdmi'`
    source=`pactl list short sources | grep bluez | awk '{print $2}'`
    pactl set-default-sink $sink
    pactl set-default-source $source
    systemctl start kodi
  • This works great, with just one flaw - volume control via bluetoth (android phone) doesnt work. I can only make it louder or quieter with alsamixer. Only mute works.

    Any ideas on this?