How come i can't play music on my iphone 4s when charging?

When i'm not charging it plays then while playing i go to plug it in and it stops playing and the volume scroll on the bottom of the screen goes away.i've also plugged in my phone while there's no music playing and when i open up the music app there's no volume scroll and when i hit play there's no sound.

When you plug your phone into the dock connector, the phone will switch its output to that dock connector-- muting the speaker and headphone jack. The volume control will disappear. (It thinks you're connected to an A/V cable or dock with audio-out and that you want your music to play through that! You don't need a volume control since you'd adjust volume on the external amplifier).

If you're using headphones, you can unplug them and plug them in again (while leaving the dock connector plugged in to recharge). The phone switches the audio output to the last thing you connected.