i haven't had it happen on iphone but occurs every once in awhile on ipad, though i have no idea why. here's my fix:
try plugging and unplugging headphones. for some reason, every so often it thinks there are headphones attached and won't play any sound. when that happens, i lock the screen, plug headphones, turn back on, and unplug. voila! sound works again.