I was having this exact issue with my iPhone 4. I couldn't find a cure for it, and mine was really random, i couldn't recreate the issue at Apple store too, so they wouldn't help me to fix the phone. What i was doing to cure it for a period of time was to hard reset the phone. But once i update the iOS to 4.3.4 back at those time, the issue was gone for ever.
I'm not sure if it's the iOS which is corrupted, where a factory restore could be able to help it, or if it's typically related to the hardware.
Now you can hard reset the iPhone, try to blow wind in the earphone outlet.
Hard reset! I have tried to reboot, respring, and clean the headphone jack. I really don't want to reset and I have to jailbreak and lnstall everything again. But I guess I will when I get to my PC. Hopefully that works. Thanks for the info.
Hard reset you wont loose anything, all you do is hold down the home and power buttons at the same time and keep holding untill you see the apple logo show up and let it go. This will reset any issues you might have.
Ok Hard Reset didn't do anything. I did however get to my PC and restore using iTunes which fixed the problem. Then I did a j/b with redsn0w using ios 5.0 and the problem came back. So I restored again using iTunes and the did a j/b with sn0wbreeze using 5.0.1 and everything is working. So I guess it was a corrupt copy of 5.0 or something. Thanks for the help!