Is there a headphone daemon for Linux like there is for maemo? It is really convenient that whenever you unplug your headphones, the media player automatically stops playing.
the hda driver, covers most of the new HD sound cards now has a way to detect plug changes. So if you did have a newer sound card, an input event happens when ever you change headphones. An input event could be mapped to a virtual keypress, such as mute. With that, just map the keypress to "MUTE" or one of the other multi-media keys.