Everything from having a hard time charging a device to no sound because your iPhone still thinks headphones are plugged in can be attributed to mystery junk accumulating in the headphone jack or in the charge/sync port (be it Lightning or 30-pin). Here's how to clean those ports and help keep stuff from building up in them:
First, get all that lint and whatever else out of the ports. Genius Bars the world over use canned air to dislodge gunk, so that might be an option if it doesn't seem like there's a lot of stuff in the ports. If canned air doesn't seem to help, you can gently insert a toothpick or other small and preferable flexible device, and use that to lightly dig out the more entrenched lint.
Twist ties can be used, or anything else that's preferably not metal so you don't scratch up the inside of your ports or damage important circuitry. A plastic dental pick comes in handy because it's reusable and easy to clean but soft enough not to hurt anything.
Once all that stuff has been liberated from the ports of your iPhone or iPad, the next step is to keep it clean. An easy way to do that is to keep the ports covered, either with a case or with some port covers, which are inexpensive and easily removable for when you actually need to plug something in. Also they come in multiples, so if you lose one it's not the end of the world. Now your iPhone and iPad shouldn't have trouble charging or playing music.