How do I prevent the media volume from changing when a headphone is plugged in?
Thought of using Tasker? I use it the other way. When ever I plugin my headphones, all volumes should come down irrespective of what ever value it was before.

I use Tasker to detect inserting the head phones and used an entry task to being down the volumes. I couldn't succeed sorting the volume levels before bringing it down so that I can restore them back in an exit task. Hence I restore them to a predetermined levels in the exit task.