I have tested my app: it starts playing a song by getting incoming call on external speaker with enough volume to make person on another side to listen what we play on our side.
But when I answer a call, the playing song stops. I want the song to be playing during call so the person on the other side can hear it.
I would appreciate any suggestion from anyone if they has also faced this problem or know a solution.
That's because while you're in a call, media playback routing will follow the voice call routing. And the default output routing for voice calls if you don't have any accessories attached is to use the earpiece.
You could try waiting for the phone state to switch to MODE_IN_CALL, and then use setSpeakerPhoneOn to change the output routing to use the loudspeaker. Note that this will also route the voice call audio to the loudspeaker, not just the media audio.
EDIT: You could try using the stream type ENFORCED_AUDIBLE (integer value 7) for your media playback. However, it might not work across all devices / all Android versions.