Airplay API

i was wondering if there is a way to identify if Apple TV went into Airplay mode? We need to detect when it goes into Airplay mode to switch to Apple TV from another source. In addition, is there a way to configure Airplay settings without using an Apple remote but rather through HTTP/Telnet or other?

Airplay API
 
 
Q