diff --git a/audio.go b/audio.go index 6c40146f..87c3ada3 100644 --- a/audio.go +++ b/audio.go @@ -176,6 +176,7 @@ func SetAudioOutputSource(useUSB bool) error { Bool("new_usb", useUSB). Msg("Switching audio output source") + oldValue := useUSBForAudioOutput useUSBForAudioOutput = useUSB ensureConfigLoaded() @@ -186,6 +187,7 @@ func SetAudioOutputSource(useUSB bool) error { } if err := SaveConfig(); err != nil { audioLogger.Error().Err(err).Msg("Failed to save config") + useUSBForAudioOutput = oldValue return err } diff --git a/jsonrpc.go b/jsonrpc.go index 326b03e0..2dc2f095 100644 --- a/jsonrpc.go +++ b/jsonrpc.go @@ -970,8 +970,13 @@ func rpcSetUsbDeviceState(device string, enabled bool) error { } func rpcGetAudioOutputSource() (string, error) { - ensureConfigLoaded() - return config.AudioOutputSource, nil + audioMutex.Lock() + defer audioMutex.Unlock() + + if useUSBForAudioOutput { + return "usb", nil + } + return "hdmi", nil } func rpcSetAudioOutputSource(source string) error {