Is the plug pushed in all the way?
Is it an older MacBook Pro? They were designed for headphone plugs with three contacts, not the iPhone's four contact plugs, The computer's ground contact must be hitting the microphone contact instead of the ground contact on the plug. Pressing the center button connects those two contacts, thus making it work. Try using a headphone extension cable. That may touch the correct plug contact.