Iphone won't play music on speaker?

My iPhone won't use the external speaker when I use the Music Player. It's NOT on silent mode. When I use the Music app, the volume control bar vanishes unless I plug in headphones. However, if I get a call, the phone WILL ring on ther external speaker and the call comes in just fine. It will not ring for a text message however. How can I fix this?

I have the iPhone 3S

Added (1). I did not drop the phone, or get water on it, it just randomly started doing it over a year ago, and all Apple told me was they couldn't figure it out and to buy a new phone.

Have you dropped it before? How long has it been doing this? My ipod did that but after 3 days it fixed on its own. You should try plugging your headphones in then out

Same issue. It must be a software thing.