I would like to use the function from Musicbox that switches between mopidy and shairport automatically in Mopidy 2 on Raspbian Jessie. I found the script “killaudio.sh” in the Musicbox repo. How is this script called from mopidy? And how does mopidy know when a shairport stream is played?
It’s shairport-sync that stops mopidy when an airplay client connects. If you look in /etc/init.d/shairport (or whatever it is) on musicbox it’ll be using the -B option to run a script that stops Mopidy before playback starts. Mopidy knows nothing about airplay/shairport.
If you are using a more recent version of shairport-sync the you can do this much neater through its config file (/etc/shairport-sync ?) rather than editing the daemon script.