Posts by incompetent-nerd

    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.