Save audio settings when switching to bluetooth
This commit is contained in:
parent
a8cfa141e4
commit
f9a5cc1d65
2 changed files with 39 additions and 9 deletions
|
@ -4,16 +4,14 @@
|
|||
|
||||
. /etc/profile
|
||||
|
||||
### REMINDER: This needs to be refactored or it will break audio on other devices.
|
||||
# Revert to default when bluetooth was still selected at last shutdown.
|
||||
# Revert to stored setting when bluetooth was still selected at last shutdown.
|
||||
# This is a workaround - headsets that auto-connect at boot tend to be
|
||||
# unreliable, so for now it's better to force a manual reconnect.
|
||||
#LAST_AUDIO_DEVICE=$(set-audio get)
|
||||
#if [[ "${LAST_AUDIO_DEVICE}" =~ ^Device.* ]]
|
||||
#then
|
||||
# set-audio set "DEFAULT (SYSTEM PROVIDED)"
|
||||
# set-audio esset "DEFAULT (SYSTEM PROVIDED)"
|
||||
#fi
|
||||
LAST_AUDIO_DEVICE=$(set-audio get)
|
||||
if [[ "${LAST_AUDIO_DEVICE}" =~ ^Device.* ]]
|
||||
then
|
||||
set-audio restore
|
||||
fi
|
||||
|
||||
if [ ! -e "/storage/.config/asound.conf" ]
|
||||
then
|
||||
|
|
|
@ -6,6 +6,31 @@
|
|||
|
||||
ES_SETTINGS="/storage/.config/emulationstation/es_settings.cfg"
|
||||
|
||||
function save_state()
|
||||
{
|
||||
ACTIVE_DEVICE=$(get_audio_device)
|
||||
ACTIVE_PATH=$(get_es_path)
|
||||
echo "$ACTIVE_DEVICE" > /tmp/active_device.cfg
|
||||
echo "$ACTIVE_PATH" > /tmp/active_path.cfg
|
||||
cp -f /storage/.config/asound.conf /tmp
|
||||
cp -f /storage/.config/asound.state /tmp
|
||||
zip -j -r /storage/.cache/audio_settings.zip /tmp/active_device.cfg /tmp/active_path.cfg /tmp/asound.*
|
||||
}
|
||||
|
||||
function restore_state()
|
||||
{
|
||||
if [ -e /storage/.cache/audio_settings.zip ]
|
||||
then
|
||||
unzip -o -d /tmp/ /storage/.cache/audio_settings.zip
|
||||
STORED_DEVICE=$(cat /tmp/active_device.cfg)
|
||||
STORED_PATH=$(cat /tmp/active_path.cfg)
|
||||
mv /tmp/asound.conf /storage/.config/
|
||||
mv /tmp/asound.state /storage/.config/
|
||||
set_audio_device "${STORED_DEVICE}"
|
||||
set_es_path "${STORED_PATH}"
|
||||
fi
|
||||
}
|
||||
|
||||
function list_audio_controls() {
|
||||
IFS=""
|
||||
ACTIVE_DEVICE=$(get_audio_device)
|
||||
|
@ -89,7 +114,8 @@ function set_audio_device() {
|
|||
# This doesn't seem necessary anymore, re-activate in case of issues.
|
||||
# bluetoothctl disconnect ${MAC}
|
||||
if bluetoothctl connect ${MAC}
|
||||
then
|
||||
then
|
||||
save_state
|
||||
cp /usr/config/asound.conf.bluealsa /storage/.config/asound.conf
|
||||
set_es_path "DEFAULT (SYSTEM PROVIDED)"
|
||||
fi
|
||||
|
@ -191,4 +217,10 @@ case $1 in
|
|||
esget)
|
||||
get_es_path
|
||||
;;
|
||||
save)
|
||||
save_state
|
||||
;;
|
||||
restore)
|
||||
restore_state
|
||||
;;
|
||||
esac
|
||||
|
|
Loading…
Reference in a new issue