If the problem only occurs with others, it's anxiety, perhaps with a good dose of shyness. I'm not a doctor, but what kind of purely physiological erectile dysfunction only strikes when the patient is with other people?
Really, the best cure for anxiety is exposure - and stressing about it is the best way to ensure that the issue will continue. Let people you're fooling around with know it can take you a while to get to full mast. (Trust me, that's not uncommon.) Then wait for nature to take its course. If you can be okay with it, the anxiety should lift enough for your dick to get hard. The more you do that, the less the anxiety will have a hold on you.
It's kind of like being pee-shy at the urinals in a bathroom. Breathe a bit and wait it out, and nature will take its course. Get all worked up over it and you'll leave frustrated.
P.S. I would disagree strongly with anyone who would suggest you try erectile dysfunction medication at this point, especially if you're not yet in middle-age or older. In my opinion, that should be an absolute last resort, and only as prescribed by a physician if you have a physical issue with maintaining erection - and that does not sound like it's the case.