My hardware configuration is Kodi HTPC connected to TV HDMI and HiFi stereo with analog input. Kodi is running as a standalone app so ALSA is preferred over PulseAudio (plus some other advantages). And last, Kodi configuration should have simple audio device selection.
In my previous installation of Kodi 15 / Fedora 22, I have used PulseAudio configured to send simultaneous audio to HDMI and analog output. Both audio outputs were never used at once and sound delay on HDMI was not a problem for my case. During Kodi 17 / Fedora 25 configuration, I figured that PulseAudio is actually not needed (someone wrote for PulseAudio as “a man in the middle” scenario) and therefore I tried to set Kodi directly with ALSA.
Here is my approach for Kodi ALSA configuration:
1) Disable pulseaudio service
Open /etc/pulse/client.conf and write two lines to the file end:
autospawn = no daemon-binary = /bin/true
This will generally disable PulseAudio. On the other hand it’s possible to disable PulseAudio only for user. Copy client.conf file from /etc directory and add “autospawn = no” at the file end.
> cp /etc/pulse/client.conf /home/[user]/.config/pulse
2) Set envirenoment variable AE_SINK in /home/kodi/.bashrc
# User specific aliases and functions AE_SINK=ALSA
With defined AE_SINK environment variable, Kodi will permanently use ALSA instead of PulseAudio (using PulseAudio in Kodi Linux installation is default option). Just keep in mind that PulseAudio should be disabled otherwise Kodi will use PulseAudio no matter of AE_SINK variable.
3) Install “Audio Profiles” Kodi add-on (and set two audio profiles)
Audio Profiles is program add-on from offical Kodi repository. After installation, in “Audio Profiles” add-on settings, enable two profiles (HDMI and Analog) and save each profile with different audio output. Configuration is easy, first step is to open “Audio output device” in Kodi settings and set analog output:
System Settings -> Audio -> Audio output device
Next step is to navigate to program add-on “Audio Profiles”, click on it and choose audio profile to save configuration. Repeat this action with HDMI output in audio settings.
4) Create keyboard shortcuts (for easy audio output switching)
Kodi uses XML keymap files in .kodi/userdata/keymaps/ directory. To create XML file, you should know XML format and key id. I used “Keymap Editor” add-on (from official repository) to create XML file with defined keys. In my case I want to toggle audio output with “z” and start radio with “r”. Here is complete keymap file for such scenario:
PlayMedia(plugin://plugin.audio.radio_de/station/Antena+Zagreb) RunScript(script.audio.profiles,0) RunScript(script.audio.profiles,0)
Full file location is /home/[user]/.kodi/userdata/keymaps/
So, to prepare XML keymap file, install “Keymap Editor” add-on and create some randomly picked actions for “r” and “z” keys. After saving settings, gen.xml file will be created in .kodi/userdata/keymaps/ directory as one long line (no newlines and indentation). With xmllint command line utility, here is how to reformat and re-indent gen.xml file:
cat gen.xml | xmllint --format - > kodi_shorcut.xml
New file is now ready for customisation. Don’t forget to uninstall “Keymap Editor” because it could change prepared keymap file.
And last trick in 3 step – how to find radio ID or plugin URL for PlayMedia:
– install program add-on “Log Viewer”
– start picked radio station
– open Log Viewer add-on and find lines related to radio_de add-on
Wish you happy Kodi time :)