Past perfect continuous
We use it when we want to say that something had been going on until a certain moment in the past.
Both actions happened in the past and no connection to present.
He had been living in the UK for 6 years when he enrolled on a teacher training course. ( He had lived there for some time and THEN he went on a course.)
The music had been playing loudly for 2 hours when the neighbours started to complain. (First the music was playing for some time and THEN the complaining has started.)
had been + verb + ing
The debate had been going on for some time when the last delegates arrived.
When I got home I saw that she had been crying.
They hadn’t been playing computer games any more when I came home.
He was sweaty and out of breath when I met him. Had he been running?
She had been working hard ‚till the day she had a cardiac arrest.
We had been doing homework before we went out to play.