Is it possible to connect another audio device when switching to another screen?

I’d like to switch to another audio device (e…g. HDMI 2) automaticly when connecting another screen (e.g. TV) to my laptop. Is that possible and howto?

Thanks,

Hans

Welcome to Manjaro forum

The simplest way to switch audio streams to a newly connected device is to use PulseAudio module module-switch-on-connect

This module is not loaded by default because it is was too aggressive for many users. The module will ignore defaults and user settings for audio streams and move all audio streams to the last audio device plugged in
PulseAudio/Documentation/module-switch-on-connect

To load the module temporarily to see if it works as expected: switching to external display when connected and switching back correctly when display is unplugged:

pacmd load-module module-switch-on-connect

If the module works as expected, it can be added to PulseAudio permanently by creating a custom user configuration:

cat <<EOT > ~/.config/pulse/default.pa
.include /etc/pulse/default.pa
load-module module-switch-on-connect
EOT