I'm going to take a guess that either the metal contacts inside the earbud jack in your G5 and/or the plug on the end of your earbuds need to be cleaned. To get a better visual, this Wikipedia page shows you how the metal contacts on the end of plug contact the metal contacts inside a typical jack:
https://en.wikipedia.org/wiki/Phone_connector_(audio)
Try getting a spray can of contact cleaner. Places like Fry's and hardware stores carry them, along with Amazon and other online retailers. Just a small, steady squirt per application is all that's needed, less is more with this stuff.
http://www.lowes.com/pd/IDEAL-Cleaning-Electrical-Switch-and-Contact-Cleaner/3127949