Hi,
I just created small and simple script to change Audio device from HDMI to BT in case the BT device is connected,and move back to HDMI when it disconnected.
I checked it only on one BT device that connected to the system, also it should be added to the startup and should run in the background:
Bash
#!/bin/bash
tvdevice="ALSA:hdmi:CARD=AMLM8AUDIO,DEV=0"
btdevice="PULSE:Default"
STAT="NA"
SetJsonTV()
{
curl -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.audiodevice","value":"ALSA:hdmi:CARD=AMLM8AUDIO,DEV=0"},"id":1}' http://127.0.0.1:80/jsonrpc > /dev/null 2>&1
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"Audio Device Change","message":"HDMI"},"id":1}' http://127.0.0.1:80/jsonrpc > /dev/null 2>&1
}
SetJasonBT()
{
curl -H "Content-type: application/json" -X POST -d '{"jsonrpc":"2.0","method":"Settings.SetSettingValue", "params":{"setting":"audiooutput.audiodevice","value":"PULSE:Default"},"id":1}' http://127.0.0.1:80/jsonrpc > /dev/null 2>&1
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"Audio Device Change","message":"BlueTooth"},"id":1}' http://127.0.0.1:80/jsonrpc > /dev/null 2>&1
}
CheckDevice()
{
#boundbt=`echo devices | bluetoothctl | grep Device | awk '{print $2}' | tail -1`
boundbt=`echo exit |bluetoothctl | grep Device | awk '{print $4}'`
devicename=`echo exit |bluetoothctl | grep Device | cut -d" " -f5-`
if [ ! -z $boundbt ] ; then
connectedbt=`hcitool con | tail -1 | awk '{print $3}'`
if [ "$connectedbt" = "$boundbt" ] ; then
[ $STAT != "BT" ] && SetJasonBT
STAT="BT"
else
[ $STAT != "HDMI" ] && SetJsonTV
STAT="HDMI"
fi
fi
}
while true ;
do
CheckDevice
sleep 10
done
Display More
Enjoy,
Robbie