At least, when it comes to AirPlay Mirroring:
https://developer.apple.com/library/safari/#documentation/Au...
Basically, you can subscribe to a notification when a second screen is connected and display there whatever you want. The French TV channels M6 and Canal+ have blocked it for a few months now. (which is absolutely stupid obviously)
As far as AirPlay from inside the default media player object, I'm not sure if it's notified to the app and I don't have an iPhone 4S or iPad2+ to check.
edit: the paragraphe "Provide Audio Metadata" from the link above seems to say that the app also knows when it's "plain" AirPlay.
They do provide a way, of course, and developers are free to disable it, and some do. On my iPad I have apps for RTE (Irish state broadcaster), TV3 (Irish private broadcaster), BBC (UK state broadcaster) and Channel 4 (UK pseudo-private broadcaster). RTE and BBC allow you to use AirPlay, TV3 and Channel 4 do not, and Channel 4 specifically mentions the fact that they don't in their FAQ, and imply that they never will.
Far weirder, the NetFlix app doesn't do AirPlay, even though they provide an AppleTV app.
Notice how touching the screen causes the UI to appear immediately, instead of the delay you'd normally expect. Also, the seek bar is much more sensitive and difficult to use.
I've been wondering why they went through the trouble of trying to make a nearly identical video player UI, but I suppose blocking AirPlay seems like a good explanation.
For movie playback there is a simple allowsAirplay property, and for mirroring they could draw an empty view (or whatever) across the 2nd screen.