How come i cant play music on my iphone 4s when charging?

When im 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.ive also plugged in my phone while theres no music playing and when i open up the music app theres no volume scroll and when i hit play theres 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.