ALSA switching

How does ALSA switch between MPD and Shairport and successfully release the DAC device?

It would be great to understand where this is done. I would like to include similar switching between MPD and Squeezelite. At current once squeezelite starts there is no stopping it.

Sent from my Nexus 5 using Tapatalk