How to record my voice and meanwhile play background music

I am building music app now, but faced some technical issue.
I played the background music and at the same time tried to record my voice.
It’s smiliar with karaoke.
But I can’t do both of them at a time.
If I try one, then another is turned off.
Who can help me, please?