Hey guys,
wow, a lot of time passed... But I also got a lot closer to the solution for my plan. I have an active keymapping that triggers a python script which switches between two sets of audio settings. It changes the output device the number of channels and the passthrough state.
keymap.xml (my remote is recognized as a keyboard):
<keymap>
<global>
<keyboard name="Samsung Remote">
<!-- 207 = "0" @ remote control -->
<key id="207">RunScript(special://profile/user_scripts/audioSwitch.py)</key>
</keyboard>
</global>
</keymap>
audioSwitch.py (based on teeedubb's script from here
# source: http://forum.kodi.tv/showthread.php?tid=199579&highlight=switch+audio
# The script toggles between two groups of settings:
# - the audio device (PI:HDMI/PULSE:Default)
# - pass-through (true/false)
# - number of channels (8(5.1ch)/2(2.1ch))
# - displays a on-screen notification.
# You need to edit the lines beginning with xbmc.executeJSONRPC and you can add/remove lines if necessary.
# To find current the audio output devices look in the XBMC log file after running the script
# (it doesn't matter if it isn't configured properly yet), it prints the current selected audio device to the log file in a JSON-RPC friendly string
# (search for "CURRENT AUDIO DEVICE" "CURRENT PASSTHOUGH STATE" or "CURRENT NUMBER OF CHANNELS").
# audio toggle script for xbmc
import xbmc
import os
tempdir = xbmc.translatePath('special://temp/')
tempfile0 = os.path.join(tempdir, 'audiooutput0')
# output (log file) to detect the current settings
print("CURRENT AUDIO DEVICE:")
print(xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"Settings.GetSettingValue", "params":{"setting":"audiooutput.audiodevice"},"id":1}'))
print("CURRENT PASSTHOUGH STATE:")
print(xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"Settings.GetSettingValue", "params":{"setting":"audiooutput.passthrough"},"id":1}'))
print("CURRENT NUMBER OF CHANNELS:")
print(xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"Settings.GetSettingValue", "params":{"setting":"audiooutput.channels"},"id":1}'))
if not os.path.isfile(tempfile0):
# settings group 0
# edit below here
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.audiodevice", "value":"PI:HDMI"}, "id":1}')
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.passthrough","value":true}, "id":1}')
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.channels","value":8}, "id":1}')
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"GUI.ShowNotification", "params":{"title":"AUDIO AUSGANG", "message":"HDMI", "image":"special://profile/user_icons/HDMI.png"}, "id":1}')
# edit above here
file = open(tempfile0, "a")
file.close()
else:
# settings group 1
# edit below here
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.audiodevice", "value":"PULSE:Default"}, "id":1}')
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.passthrough","value":false}, "id":1}')
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.channels","value":2}, "id":1}')
xbmc.executeJSONRPC('{"jsonrpc":"2.0", "method":"GUI.ShowNotification", "params":{"title":"AUDIO AUSGANG", "message":"Bluetooth", "image":"special://profile/user_icons/BT.png"}, "id":1}')
# edit above here
os.remove(tempfile0)
Display More
That works just fine (you can also see the chhanges in the settings menu, too) and I am very happy about it.
What's left to do is to force connect the BT speaker which should be already paired and trusted (I don't think it is necessary to script pairing and trusting, too).
Therefore I want a message window to tell the user to turn on the speaker an when it's turned on the user has to klick "OK" or "Turned on" or something like that). A "Cancel" button should stop the whole process.
After "OK" was pressed, a command will be sent to connect the speaker using it's MAC address, e.g.
when unsing ssh (as found here and here). I don't know how to do this in python and / or via json (yet?).
The response of that command should be visible for the user via notification (e.g. "BT speaker connected" / "Could not connect BT speaker").
I would insert this procedure before setting the audio output device to PULSE:Default (BT) and only change the output settings if the user didn't press "Cancel" and the speaker was successfully connected to the Raspberry Pi 3.
I'll try to figure out how to implement all this and keep the thread up to date.
Anyways, if anyone of you has help to offer I'll appreciate it.