OK, these sentences aren't really clear. Let me just try to explain this to you. I had been speaking to my friend until X "had been really tries to say something was happening before/until X; X happened after the event following had been[speaking to my friend]" So, essentially it means you were speaking[continued to speak- continuous action] until something happened afterwards.
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.