[Updated November 2021]
Bluez-alsa allows you to stream audio both to and from your OSMC device. We have now integrated bluez-alsa into OSMC as a replacement for our a2dp package which is deprecated. Our Kodi v19 builds include bluez-alsa. If you are still on v18.9, you can install it on Vero 4k or RPi 2/3 with:
sudo apt-get install armv7-bluezalsa-osmc
and re-boot to get the bluealsa service started.
If you have previously installed one of our older BT audio packages, you will need to remove it/them (see below).
Streaming to your OSMC device
Just use My OSMC ā Networking ā Bluetooth to pair and trust your source (eg a smartphone). You should now be able to choose your OSMC device in the list of BT devices on your smartphone.
The stream goes to your default audio device which is HDMI. Make sure Kodi isnāt trying to use HDMI audio at the same time - turn off āKeep audio device aliveā in Settings->System->Audio. See below for streaming to other audio devices.
Streaming from your OSMC device
Since our November 2021 update with Kodi 19.3, this works without having to write ALSA config files. Just pair and connect your BT audio device using My OSMC or bluetoothctl and an item āBluetooth Audioā will appear in Settings->System->Audio->Audio output device whenever a BT device is connected.
If you have more than one BT audio device and want each device name to show up in Kodiās device selection dialogue you must make a custom ALSA configuration file. See below. Otherwise, do not use a .asoundrc file for Bluetooth.
Connecting using bluetoothctl
If you canāt connect using My OSMC, try using the command bluetoothctl
. Start it from the command line, make your BT device discoverable, then type
agent on
scan on
Wait for your headphones/speaker to show up, then, using its MAC instead of 01:23:45:67:89:ab (bluetoothctl supports tab completion so type, eg 01 Tab):
pair 01:23:45:67:89:ab
trust 01:23:45:67:89:ab
connect 01:23:45:67:89:ab
scan off
agent off
quit
Writing a custom ALSA config file
If the default setup doesnāt work for your device or you have special requirements you will need to write a configuration file for ALSA. You need to be familiar with the commandline and a text editor (eg nano).
You need to make a file called .asoundrc in your home directory (/home/osmc). Your .asoundrc file should have entries like this
pcm.mybtspeaker {
type bluealsa
device "01:23:45:67:89:AB"
profile "a2dp"
hint { show on description "My BT Speaker"}
}
mybtspeaker
can be any name you like, as long as itās unique.
01:23:45:67:89:AB
is a bluetooth MAC address. You need to substitute the MAC address of your speaker/headphones. You may see this when you connect it using My OSMC. If not, use bluetoothctl devices
to find it.
My BT Speaker
can also be anything you like and it will show up in Kodiās list of audio devices.
Make a separate entry in .asoundrc for each of your BT audio devices.
After saving the .asoundrc file, re-start Kodi (Power->Exit) or disconnect and re-connect your BT device so that Kodi knows itās available.
Streaming from BT to a device other than HDMI
The streaming function is provided by bluealsa-aplay
which is started by systemd. To stream from your phone to, say, a USB DAC you can edit the systemd unit file sudo nano /lib/systemd/system/bluealsa-aplay.service
like this (ie add the -D option to the ExecStart line):
[Unit]
Description=A2DP Playback
After=bluealsa.service syslog.service
Requires=bluealsa.service
StopWhenUnneeded=true
[Service]
ExecStartPre=/bin/sleep 3
ExecStart=/usr/bin/bluealsa-aplay -D front:CARD=Audio --profile-a2dp 00:00:00:00:00:00
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=A2DP-Playback
Restart=on-failure
[Install]
WantedBy=bluetooth.target
then
sudo systemctl daemon-reload
sudo systemctl restart bluealsa-aplay
This assumes your DAC is reported like this by aplay -L
default:CARD=Audio
USB2.0 High-Speed True HD Audio, USB Audio
Default Audio Device
USB cards are usually called āAudioā. If yours is different, or for other audio cards like Pi HATs, substitute what aplay -L
tells you after CARD=
.
You may have to install alsa-utils which provides aplay
:
sudo apt-get update
sudo apt-get install alsa-utils
Removing older BT audio packages
OSMC used to ship a package called a2dp-app-osmc which used a customised version of pulseaudio. This needs to be removed as we no longer support pulse. Also remove any previous version of this bluez-alsa based package.
sudo dpkg -r armv7-bluez-alsa-app-osmc
sudo dpkg -r armv7-bluez-alsa-osmc
sudo apt-get --fix-broken install
sudo apt-get remove --purge a2dp-app-osmc
sudo apt-get remove --purge pulseaudio-module-bluetooth
sudo apt-get remove --purge pulseaudio
Building from source
We do not build bluez-alsa with codecs that are subject to licencing restrictions. To support extra codecs, you will need to obtain the libraries and build the bluez-alsa package from source. You can build the package on your OSMC device as follows:
- set up a build environment as described here
- in the OSMC git tree you have cloned, navigate to osmc/package/bluezalsa-osmc and edit build.sh to add the codecs you need. The codecs that bluez-alsa supports are described on the bluez-alsa wiki.
As an example, these are the changes you need to add aptX and LDAC support.
diff --git a/package/bluezalsa-osmc/build.sh b/package/bluezalsa-osmc/build.sh
index dfb0837df..dcca4a39c 100644
--- a/package/bluezalsa-osmc/build.sh
+++ b/package/bluezalsa-osmc/build.sh
@@ -22,6 +22,9 @@ then
handle_dep "libsbc-dev"
handle_dep "libglib2.0-dev"
handle_dep "libfdk-aac-dev"
+ handle_dep "libopenaptx-dev"
+ handle_dep "libldacbt-enc-dev"
+ handle_dep "libldacbt-abr-dev"
handle_dep "automake"
handle_dep "libtool"
handle_dep "pkg-config"
@@ -29,7 +32,7 @@ then
echo "Package: ${1}-bluezalsa-osmc" >> files/DEBIAN/control
pushd src/bluez-alsa*
autoreconf -vif .
- ./configure --enable-aac --with-alsaplugindir=/usr/lib/arm-linux-gnueabihf/alsa-lib/ --with-alsaconfdir=/usr/share/alsa/alsa.conf.d
+ ./configure --enable-aac --enable-aptx --with-libopenaptx --enable-ldac --with-alsaplugindir=/usr/lib/arm-linux-gnueabihf/alsa-lib/ --with-alsaconfdir=/usr/share/alsa/alsa.conf.d
if [ $? != 0 ]; then echo -e "Configure failed!" && umount /proc/ > /dev/null 2>&1 && exit 1; fi
$BUILD
if [ $? != 0 ]; then echo -e "Build failed!" && exit 1; fi
Run the build script by typing make armv7
. This will produce a .deb that you can install with
sudo dpkg -i armv7-bluezalsa-osmc.deb
. This package will be overwritten the next time bluezalsa-osmc is updated so you will have to repeat the custom build if that happens.