How do I make the audio switch between hdmi output and the headphone jack automatically?

Is there a way that I can make the audio switch between the headphone jack and my hdmi output automatically? For some reason it can only be switched manually. I don’t know much about Pulseaudio so I’m sorry if this has an obvious solution.