Keymap “mute HDMI audio output” setting

not sure whether I fit into this thread, but didn’t want to create new topic, so will try here first.
For audio playback, I am using two setups

  1. Vero → HDMI → TV (regular watching)
  2. Vero → toslink → DAC → amplifier (Hi-Fi and movies with high res audio)

I know I can disable HDMI voice through audio option, but this is quite deep Kodi submenu and as I am lazy to toggle this setting every time I go back to setup 1, I rather disable TV speakers on TV remote.

Would it be possible to map this Kodi/OSMC? HDMI voice on/off option from this down deep menu into the Voice/Sound menu accessible right from the video playback? I mean that menu where you can choose audio stream during playback? That would make my audiophile life way easier.

You didn’t, so I moved this to a new topic for you.

I’m not sure what you mean by “HDMI voice”. If you mean toggle between passthrough and PCM output then yes you can keymap that with the “audiotoggledigital” action. See the following thread…

If you mean where you select which output device, then maybe, but not so simple. I’ve not tried it but if you search around you should find there is some kind of audio switcher add-on that you can install and that allows you to switch between several different set of audio settings. It requires more than just a couple click install, but apparently it works, I don’t remember the name off hand.

toslink can’t do high res audio, you would need to use HDMI for that. If your amplifier is an AVR with a passthrough option this would be the way to go IMO.

thank you. the option I had on my mind was “mute HDMI audio output” from System/Display menu.
I am using 2.0 setup with very old Marantz PM-72 amplifier that doesn’t have HDMI, but only cinches as line in. So I connect Vero (or other digital source) to DAC via toslink and through cinch cable to amplifier. Voice is going both through hdmi and toslink, unless I disable it either via mentioned Kodi submenu or via disabling TV speakers (which is quicker).
So I though if the “mute hdmi audio output” would be as an option in “audio setting” during playback, then it would be single click on Vero remote.

It looks like someone worked out a pretty good solution here…

https://forum.kodi.tv/archive/index.php?thread-341196.html

That solution is pretty nice. I think it only actually takes effect when playback is stopped so keep that in mind when testing it.

I am sorry, as I am not coder, I can only barely read some simple bash scripts, definitely not python. I also have Vero just couple of weeks, so I might miss the context here.
I understand that first part of code adds either audio_off or on parameter into /sys/class/amhdmitx/amhdmitx0/config
But as there is no /home/osmc/scripts/HDMI_toggle.py on my Vero, I assume this is all about mapping new function to the remote’s buttons and when looking onto the first link you provided in this thread ( OSMC Remote - Long Press Keymap Guide) I also guess I have to install Keymap Editor and start there - which might create the missing files/directories that I will adjust later with provided code. I believe I can make it, just need to go through the Kodi’s keymap wiki first.
Please kick me, in case this approach is totally wrong.

To be complete, I am adding the original post here.

Code:
echo audio_off > /sys/class/amhdmitx/amhdmitx0/config
echo audio_on > /sys/class/amhdmitx/amhdmitx0/config

Added a key mapping
Code:
XBMC.RunScript(/home/osmc/scripts/HDMI_toggle.py)

Content of HDMI_toggle.py:
Code:
import subprocess

file = open("/home/osmc/scripts/HDMI_status.txt", “r”)
inhalt = file.read()
file.close()

file = open("/home/osmc/scripts/HDMI_status.txt", “w”)

print(inhalt)

if “off” in inhalt:
subprocess.call(["/home/osmc/scripts/HDMI_on.sh"])
file.write(“on”)

else:

subprocess.call(["/home/osmc/scripts/HDMI_off.sh"])
file.write("off")

file.close()

You can install samba server on your Vero and make the files on your PC if you prefer but I’ll just walk you through doing it via the terminal since your going to have to go there to change file permissions anyways. You can find instructions on how to ssh into your Vero [here]

In the terminal type each line and then hit return. Also note that case sensitivity is important.

cd
mkdir scripts
cd scripts
nano HDMI_off.sh

This last command will drop you into a text editor. Assuming your doing this via ssh on a PC you should be able to just copy/paste this from this page. When your done editing the file you can ctrl+x, then y, then press enter to save the file and close nano. The text that needs to be in the first file is…

#!/bin/bash

echo audio_off > /sys/class/amhdmitx/amhdmitx0/config

And for our next file
nano HDMI_on.sh

which needs the following…

#!/bin/bash

echo audio_on > /sys/class/amhdmitx/amhdmitx0/config

And the python script
nano HDMI_toggle.py

Which needs the following…

import subprocess

file = open("/home/osmc/scripts/HDMI_status.txt", "r")
inhalt = file.read()
file.close()

file = open("/home/osmc/scripts/HDMI_status.txt", "w")


print(inhalt)

if "off" in inhalt:
    subprocess.call(["/home/osmc/scripts/HDMI_on.sh"])
    file.write("on")

else:

    subprocess.call(["/home/osmc/scripts/HDMI_off.sh"])
    file.write("off")

file.close()

Then run these at the terminal…
chmod +x *
echo on >HDMI_status.txt

And now we are just left with making our keymap file which will need to start with figuring out what button you want to use for this. If your using the Vero remote then it may be a bit more complicated due to how heavily customized the keymap for that is. If your using something other than the OSMC remote you can you the keymap editor to find the key id, but you will not be able to program this with that add-on. Additionally if you use keymap editor after making this keymap it will mess it up. The following is a keymap for the OSMC remote, or any other remote that has longpress ability to activate this command when you hold down the OK/select button…

nano ~/.kodi/userdata/keymaps/hdmi_mute.xml

<?xml version="1.0" encoding="UTF-8"?>
<keymap>
        <global>
                <keyboard>
                        <return mod="longpress">RunScript(/home/osmc/scripts/HDMI_toggle.py)</return>
                </keyboard>
        </global>
        <FullscreenVideo>
                <keyboard>
                        <return mod="longpress">RunScript(/home/osmc/scripts/HDMI_toggle.py)</return>
                </keyboard>
        </FullscreenVideo>
        <Videos>
                <keyboard>
                        <return mod="longpress">RunScript(/home/osmc/scripts/HDMI_toggle.py)</return>
                </keyboard>
        </Videos>
        <Home>
                <keyboard>
                        <return mod="longpress">RunScript(/home/osmc/scripts/HDMI_toggle.py)</return>
                </keyboard>
        </Home>
        <VideoPlaylist>
                <keyboard>
                        <return mod="longpress"/>
                </keyboard>
        </VideoPlaylist>
</keymap>

And that should be working as soon as you…

kodi-send -a reloadkeymaps

I tested this, it works, and it doesn’t care if a file is already playing or not, it switches immediately when (with an OSMC remote and the keymap file above) you hold down the OK button. It does not trigger the setting in the GUI to show that it is on or off. That setting will be the setting when kodi is restated. The script will only temporarily toggle the state back and forth.

1 Like

Wow, it works like a charm! Thank you very much darwindesign. That is much appreciated.

1 Like

Audio Profiles.

https://kodi.tv/addons/matrix/script.audio.profiles

I remembered the name because I maintain it. '-)

2 Likes

You welcome. If that particular key isn’t ideal for you let me know what would be better and I can help you out with a different keymap.

Thanks, that’s exactly the one I was thinking of.

“OK” is absolutely fine, but I was thinking where exactly did you set up that key as I can’t see any particular key id or so in the files I was creating.
And by the way, glad there’s vi editor available. At least I could use something I am used to.

All buttons/keys have a key id, some also have a name, either is okay to use in a keymap, names are much easier to read and understand what your doing. The name of the “OK” button on that remote is “return”. The extra complication in that map is that in order to get that button to work across relevant parts of the GUI I had to overwrite functions that were in those other window ids. It might make more sense if you look at the keymap that it is stacking on top of…

which is stacking on top of

1 Like

Righ, now I understand. Of course “return” is more intuitive, however “61453“ would probably ring the bell on my side earlier as this looks like real key id. :slight_smile: Anyway, Thanks again for detailed explanation. :+1:

1 Like

Just wanted to share, that all works fine with just one issue. If video is paused for half a minute or longer (I think short couple sec. pauses are ok), then this setting resets back to the original, so in case “mute HDMI audio output = off” is default and you toggle this during playback, then after the pause it goes back to off and needs to be toggled again after playback is resumed.

Maybe try adjusting settings>system>audio>keep audio device alive

Not really sure. Maybe @grahamh has an idea.

@grahamh has no idea. The setting seems to stick if I set it in the GUI but not if I issue the commands on the command line. Sam introduced the global setting in Kodi and it doesn’t take effect until a video is started. I guess that setting is queried when a video starts (or restarts from pause?).

It will need some digging in the code.

Yeah, or even when audio stream is changed.

You need to toggle the Kodi setting itself, not the underlying kernel parameter, since kernel mutes and unmutes audio to avoid pops when changing resolutions, etc.

There doesn’t seem to be a Kodi Action to set a setting directly. I had to resort to JSON:

osmc@vero4kp2:~$ curl "localhost:80/jsonrpc" -u osmc:osmc -H "content-type:application/json" -d '{ "jsonrpc": "2.0", "method": "Settings.SetSettingValue", "params": {"setting":"videoscreen.mutehdmi", "value": true}, "id": 1 }'
{"id":1,"jsonrpc":"2.0","result":true}

osmc@vero4kp2:~$ curl "localhost:80/jsonrpc" -u osmc:osmc -H "content-type:application/json" -d '{ "jsonrpc": "2.0", "method": "Settings.GetSettingValue", "params": {"setting":"videoscreen.mutehdmi"}, "id": 1 }'
{"id":1,"jsonrpc":"2.0","result":{"value":true}}osmc@vero4kp2:~$

Someone handier with Python than me should be able to write HDMI_toggle.py to read the setting direct (instead of using HDMI_status.txt) and issue the appropriate SetSettingValue value.

Remaining problem is the setting doesn’t take effect until audio is restarted. So you need to toggle sound then start your video (or pause-wait-restart). We can fix that in a future release.

2 Likes

The existing solution is doing a toggle and calling bash scripts where the json request could be added. By running both commands that should eliminate the non-change during playback issue.

1 Like