Posts by alex.caserini

    If you've investigated the problem and already figured out the fix/solution, perhaps send us a pull request?

    Yes, I can try to prepare a pull request.

    I have already identified and tested a minimal local fix on my LibreELEC 12.2.1 / Raspberry Pi 4 setup. The issue seems to be in service.bluetooth-audio: it sets Kodi’s audio output device to the incomplete value:

    Code
    PULSE:Default

    while Kodi works correctly when the full validated PulseAudio device id is used:

    Code
    PULSE:Default|Bluetooth Audio (PULSEAUDIO)

    After patching default.py locally and updating the add-on setting, Bluetooth audio now works correctly after reboot and auto-connect, and Kodi shows PulseAudio correctly instead of falling back to ALSA.

    Before I open a PR, could you please confirm which source repository and branch I should target for service.bluetooth-audio?

    On my installed system the affected file is:

    Code
    /storage/.kodi/addons/service.bluetooth-audio/default.py

    but I would like to make sure I submit the fix against the correct upstream source tree.

    Sorry I'm not a developer :)

    Hello,

    I would like to report a reproducible Bluetooth audio issue on LibreELEC/Kodi.

    Hardware

    Device: Raspberry Pi 4
    GPU: Broadcom VideoCore VI / Raspberry Pi 4 integrated GPU
    Bluetooth audio device used for testing: JBL GO 2
    Original target device: car Bluetooth audio/head unit
    Storage: USB SSD used only as media storage; system boots from microSD

    Software

    LibreELEC version: 12.2.1
    Bluetooth Audio add-on: service.bluetooth-audio v12.2.0.1
    PulseAudio version shown by pactl info: 17.0

    Problem summary

    When using Bluetooth audio through LibreELEC/Kodi, the Bluetooth connection is established correctly and PulseAudio creates the expected Bluetooth sink, for example:

    Code
    bluez_sink.70_99_1C_D5_6C_A7.a2dp_sink

    However, Kodi sometimes shows ALSA as the active audio output device, and MP3 playback has audio interruptions or can stop when entering the audio settings screen.

    The issue appears to be caused by the service.bluetooth-audio add-on setting Kodi’s audio output device to the incomplete value:

    Code
    PULSE:Default

    instead of the full PulseAudio device value recognized by Kodi:

    Code
    PULSE:Default|Bluetooth Audio (PULSEAUDIO)

    Steps to reproduce

    1. Boot LibreELEC on Raspberry Pi 4.
    2. Connect a Bluetooth audio device using LibreELEC Bluetooth configuration.
    3. Start Kodi and play an audio file, especially MP3.
    4. Open Kodi audio settings.
    5. In some cases Kodi shows ALSA as the selected output device.
    6. Playback may stop or become unstable.
    7. Manually changing the audio output in Kodi from ALSA to PulseAudio immediately restores correct audio playback.

    Observed behavior

    Before the workaround, Kodi could end up with this setting in guisettings.xml:

    Code
    <setting id="audiooutput.audiodevice">ALSA:@|Default (vc4-hdmi-0 MAI PCM i2s-hifi-0) ()</setting>

    At the same time, PulseAudio still had the Bluetooth sink available, but it was suspended and there was no active Kodi stream:

    Code
    Default Sink: bluez_sink.70_99_1C_D5_6C_A7.a2dp_sink
    bluez_sink... SUSPENDED

    Kodi log also showed that the Bluetooth Audio add-on was setting the device to the incomplete value:

    Code
    service.bluetooth-audio: setting default audio device "PULSE:Default" on start

    When the audio output was manually changed from the Kodi GUI to PulseAudio, the correct value was written:

    Code
    <setting id="audiooutput.audiodevice">PULSE:Default|Bluetooth Audio (PULSEAUDIO)</setting>

    and PulseAudio showed an active Kodi stream:

    Code
    application.name = "KodiSink"
    media.name = "kodi audio stream"
    Sink: bluez_sink...

    Expected behavior

    The Bluetooth Audio add-on should set Kodi’s audio output device to the full PulseAudio device string used by Kodi:

    Code
    PULSE:Default|Bluetooth Audio (PULSEAUDIO)

    instead of:

    Code
    PULSE:Default

    Kodi should consistently show PulseAudio as the selected audio output device after Bluetooth auto-connect, and audio playback should not fall back to ALSA or stop when entering the audio settings screen.

    Investigation

    The relevant add-on file is:

    Code
    /storage/.kodi/addons/service.bluetooth-audio/default.py

    The problematic line was found here:

    Code
    self.pulsedevice = 'PULSE:Default'

    The add-on data file also contained the incomplete value:

    Code
    /storage/.kodi/userdata/addon_data/service.bluetooth-audio/settings.xml

    with:

    Code
    <setting id="audiodevice">PULSE:Default</setting>

    Workaround / local patch

    Changing the add-on code from:

    Code
    self.pulsedevice = 'PULSE:Default'

    to:

    Code
    self.pulsedevice = 'PULSE:Default|Bluetooth Audio (PULSEAUDIO)'

    and updating:

    Code
    <setting id="audiodevice">PULSE:Default|Bluetooth Audio (PULSEAUDIO)</setting>

    in:

    Code
    /storage/.kodi/userdata/addon_data/service.bluetooth-audio/settings.xml

    fixed the problem.

    After reboot:

    • Bluetooth connects automatically.
    • Kodi shows PulseAudio correctly in the audio settings page.
    • guisettings.xml keeps the correct value.
    • PulseAudio sink is active.
    • Audio playback works normally.
    • The previous ALSA fallback no longer occurs.

    Kodi log after the patch shows:

    Code
    service.bluetooth-audio: setting default audio device "PULSE:Default|Bluetooth Audio (PULSEAUDIO)" on start
    PulseAudio: Opened device Default in pcm mode

    Additional logs and outputs

    I can provide a full debug log if needed.

    Relevant commands used during testing:

    Code
    pactl info
    pactl list sinks short
    pactl list sink-inputs
    grep -iE 'audiooutput.audiodevice|audiooutput.passthrough' /storage/.kodi/userdata/guisettings.xml
    grep -iE 'service.bluetooth-audio|PulseAudio|OpenSink|ALSA|PULSE' /storage/.kodi/temp/kodi.log
    dmesg
    lsusb

    Suggested fix

    Please consider updating service.bluetooth-audio so that it stores and applies the full Kodi PulseAudio device identifier:

    Code
    PULSE:Default|Bluetooth Audio (PULSEAUDIO)

    instead of the shorter/incomplete value:

    Code
    PULSE:Default

    or alternatively dynamically retrieve the exact PulseAudio device identifier from Kodi’s enumerated audio devices before applying the setting.

    Below is the "production-grade" procedure from scratch, which radically eliminates the ordering cycle error on LibreELEC.
    The principle is simple: kodi-avrcp must never be directly linked to kodi.service, kodi.target, or graphical.target.
    In production, it is started via a systemd post-boot timer.

    Production Installation (LibreELEC) – anti-ordering-cycle version

    1) Prerequisites on LibreELEC

    Enable SSH (if needed): LibreELEC Settings → Services → SSH ON
    Enable Kodi JSON-RPC via HTTP: Kodi Settings → Services → Control
    Allow remote control via HTTP: ON
    Port: 8080

    Quick verification (from LibreELEC):

    curl -s -u kodi:kodi -X POST -H 'Content-Type: application/json' \
    --data '{"jsonrpc":"2.0","method":"JSONRPC.Ping","id":1}' \
    http://127.0.0.1:8080/jsonrpc
    Expected: pong.

    2) Compile on PC (Ubuntu) for the correct architecture

    On LibreELEC:

    uname -m


    If it is armv7l:

    CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 \
    go build -trimpath -ldflags="-s -w" -o kodi-avrcp


    If it is aarch64:

    CGO_ENABLED=0 GOOS=linux GOARCH=arm64 \
    go build -trimpath -ldflags="-s -w" -o kodi-avrcp


    Check:

    file ./kodi-avrcp

    2.2) Copy to LibreELEC
    scp ./kodi-avrcp root@IPLIBREELEC:/storage/.config/kodi-avrcp


    On LibreELEC:

    chmod +x /storage/.config/kodi-avrcp
    ls -l /storage/.config/kodi-avrcp

    3) "Root" cleanup (removes links that generate cycles)

    On LibreELEC:

    # Stop/disable any old versions
    systemctl disable --now kodi-avrcp.service 2>/dev/null || true
    systemctl disable --now kodi-avrcp.timer 2>/dev/null || true
    systemctl reset-failed kodi-avrcp.service 2>/dev/null || true

    # (Optional but recommended) if kodi-autostart creates cycles, disable it
    systemctl disable --now kodi-autostart.service 2>/dev/null || true
    systemctl reset-failed kodi-autostart.service 2>/dev/null ||
    [cite_start]true [cite: 8]

    # Remove any old units in /storage/.config/system.d
    rm -f /storage/.config/system.d/kodi-avrcp.service
    rm -f /storage/.config/system.d/kodi-avrcp.timer


    If you created drop-ins for kodi in the past (rare but possible), check:

    ls -l /storage/.config/system.d/kodi.service.d 2>/dev/null || true


    If files exist there that mention kodi-avrcp/kodi-autostart, delete them.

    4) Create the kodi-avrcp.service (without Kodi/graphical.target)

    On LibreELEC:

    mkdir -p /storage/.config/system.d

    cat > /storage/.config/system.d/kodi-avrcp.service <<'EOF'
    [Unit]
    Description=Kodi AVRCP metadata bridge (Kodi JSON-RPC -> BlueZ RegisterPlayer)
    After=bluetooth.service
    Wants=bluetooth.service

    [Service]
    Type=simple
    # Delay to allow time for BT and Kodi to be ready, without direct dependencies
    ExecStartPre=/bin/sh -c 'sleep 12'
    ExecStart=/storage/.config/kodi-avrcp
    Restart=always
    RestartSec=2

    Environment=KODI_URL=http://127.0.0.1:8080/jsonrpc
    Environment=KODI_USER=kodi
    Environment=KODI_PASS=kodi
    Environment=BLUEZ_ADAPTER=hci0
    # (optional) Environment=POLL_MS=900

    EOF


    Note: the [Install] WantedBy=... section is intentionally missing here.


    5) Create and enable the timer (post-boot start)
    This is the point that eliminates the cycle.

    cat > /storage/.config/system.d/kodi-avrcp.timer <<'EOF'
    [Unit]
    Description=Start kodi-avrcp after boot (avoid ordering cycles)

    [Timer]
    OnBootSec=25
    Unit=kodi-avrcp.service

    [Install]
    WantedBy=timers.target
    EOF


    Activate:

    systemctl daemon-reload
    systemctl enable --now kodi-avrcp.timer
    systemctl status kodi-avrcp.timer -l --no-pager

    6) Immediate test (without rebooting)

    Manual start:

    systemctl start kodi-avrcp.service
    systemctl status kodi-avrcp.service -l --no-pager
    journalctl -u kodi-avrcp.service -n 60 --no-pager


    Expected: a line like “Registered MPRIS player …”.

    Is LE or the head-unit the playback device? (where is media read, what is controlling playback) .. What's the OS/capabilities of the (factory, aftermarket?) head unit in the car?

    Hi,

    The situation is:

    First: usb SSD --> LE rpi4 usb --> Bluetooth dongle ---> (only audio) --->car entrainment

    Second: internet --> android phone --> Bluetooth --> car entrainment

    in both situation car entrainment is like a Bluetooth speaker.

    but.. if I use a android phone on the car display I can se: Title, artist, cover, remaining time, etc... (now playng information)

    I like to see all information even with LE.

    TNKS

    Hi all,

    now I've a mobile media center with 1 Rpi4, 2 SSD (and another nerd option.. :) ).

    RPI actual is connected to my car entertainment system by Bluetooth...

    I'm looking a way to see "now playing" information on car display (like a connection with my android phone)

    there is a solution with LE (or another tricks?)

    TNKs in advance...

    Ciao

    Alex