How to detect whether an audio output jack is connected to a headphone or an aux input?
What you want to detect is the impedance of the "load".  In one case the load is the headphones.  In another case the load is the aux input of the device.  

With the headphones, the impedance will typically be less than 1K Ohm (and as low as 4 ohms).  If it is feeding an aux input then the impedance will be greater than 1K, and possibly as high as 1 mega-ohm.

Measuring the impedance is difficult, since the impedance changes depending on frequency.  And frequency depends on the music or audio program that is being "played".  The normal way is to measure both the voltage and current to the load and then do some crazy complex math to calculate the impedance.  Most of the time this is done by feeding the voltage and current into an ADC, and then to a DSP.

There might be a way to do a cheap and dirty version that doesn't require an ADC or DSP, if all you want to know is if it's greater or less than 1K Ohm.  I haven't given this much thought, however, since everything I've done has focused on the accurate version and not a quick and dirty version.