It's most likely a hardware problem rather than a software problem. I have a phone with a really shitty headphone plugin, and I can only hear out of headphones if you push on the jack at a certain angle.
I'd suggest getting it looked at, or checking if anyone on the internet has the same problem.