I have an essentially new MacBook Pro with Lion and all updates applied, and am wondering if this is a hardware or software problem. Essentially with something plugged into the headphone jack, things work as they are supposed to for a while, then the sound will switch back to internal speakers, or sometimes 'digital out' (I can watch it change in the system settings), and then often switch back. It doesn't seem to follow any sort of pattern or be related to any specific application that could be open, and happens with different sources of audio (iTunes, streaming from the web), and different external speakers or headphones plugged in. It does seem to be better for a while each time I unplug and plug back in the jack.
It sounds like a hardware problem in the jack. If you can put pressure on the external part of the plug and change it: cause static or breakup it's probably a hardware problem in the jack.
If you had said you only tried one set of headphones then I'd have said it's probably a problem in the headphone plug but if it's multiple phones and speakers then it's probably the jack.
There's a sensor in that jack that monitors if something's in it or not to switch off the internal speakers. The if there's continuous sound, just switching from internal to external the problem may be that sensor. If the sound cuts out from both internal and external once in a while it's probably the jack.
If the MacBook Pro is still under warranty I'd have Apple look at it, they'll swap motherboard to make it right if it's a hardware problem at no cost to you.