From what you describe it sounds as if you have a mechanical problem with the headphone socket.
These sockets are designed with very simple switches in them - actually just bits of springy metal that make contact to the internal speakers when the plug is removed. These contacts can be problematic, to say the least, and can stop working for any number of reasons, from dirt build up on the contact surfaces to loss of springiness and/or distortion caused by the plug being pulled yo one side for some reason.
|