I have an iPhone 4 with some slight water damage. The only issue is that when I am listening on headphones, occasionally it thinks that it is docked (which silences the headphones), then half a second to 10 seconds later, it thinks it has been removed from the dock that it was never connected to and thus pauses the audio. Since all this happens in the OS while it monitors the status of the headphone jack and the media dock, it would be very easy to write a program to tell it to stop polling the media dock, and thus the faulty dock detection switch would be ignored. So, has someone already written an iPhone app that is on Cydia that would let me turn off the dock detector switch?
Unfortunately, this would require some very specific code that goes beyond anything I've seen on Cydia. That's not to say that a solution does not (or will not by the time I finish this post) exist. However, through my research and experience, this is handled by code much deeper in iOS than most Cydia apps care to touch. I wish I could offer a solution, but unfortunately, I think the only "real" solution is repair or replacement. Sorry. :(
Good luck and happy listening!
Perhaps more of a workaround than an answer, and it may only solve half your problem (plus a bit late), but anyway: my suggestion is to try a different music player. The standard Apple iPod app (and most other audio players) not only redirects audio when docked, but stop playing when undocked, as you noted in your description. However, there are some audio player apps that don't stop playing when undocked. Just one example is the free Cydia app MyFile (just tried this with my iPod and dock). So you'll still have the "half a second to 10 seconds" silence, but won't have to press play afterwards.
I'd use eBay to swap the phone. Upgrade to a 4S
People will buy iPhones that are in much worse condition , and in one day auctions.
I followed a tip in a reddit forum somewhere.. Using iFile, go to system --> Library --> LaunchDaemons and there search for a file "com.apple.iapd.plist". Make a backup of that first and then delete it. When you reboot your system, voila! you should have your audio back. It worked for me. I guess it deletes the docking detecting algorithm so make sure you back up the file in case you have to use some dock in the future.!