In my opinion as an EE there would be some reasonably reliable ways to detect either a line or headphone connection. Headphone impedances are typically between 16 and 600 Ohms, and line impedance is typically in the 10&#x27;s of kOhm range. That&#x27;s one way to differentiate. There has to be an output signal (presumably audio) first, however. 
Another way is to apply a very small DC current (that would certainly not damage headphones, so I would guess in the micro-ampere range) and check if there is continuity or measure the DC resistance of the load outright. For line inputs, as they&#x27;re usually AC-coupled, DC resistance would be infinite, and for (DC coupled) headphones it is very low. It&#x27;s an interesting subject and I wouldn&#x27;t be surprised if there are some patents involved.