How do you have Ubuntu properly manage the audio output device currently in use? [duplicate]

I list sources and sinks as follows:

pactl list sources
pactl list sinks

The output I get is:

...
    Ports:
        analog-input-internal-mic: Internal Microphone (priority: 8900)
        analog-input-headphone-mic: Microphone (priority: 8700)
        analog-input-headset-mic: Headset Microphone (priority: 8800)
...
    Ports:
        analog-output-speaker: Speakers (priority: 10000)
        analog-output-headphones: Headphones (priority: 9000, available)

How do I change the priorities listed above and have them fixed at what I change them to? Note that I am not looking to set a default source and sink or to delete unwanted sources or sinks, I just want to be able to assign them different priorities.


Solution 1:

First, use the following command to see the list of cards and ports:

pactl list sinks

Then, run:

sudo vim /usr/share/pulseaudio/alsa-mixer/paths/analog-output-headphones.conf

to modify the priority (that value is multiplied by 100).