VoiSmart / pjsip-android

SIP Service for Android based on PJSIP
http://www.pjsip.org/
Apache License 2.0
288 stars 140 forks source link

[ISSUE] Connect to PJSIP call while having other Voip call ongoing Android. Cannot hear in PJSIP call #198

Open mudassirzulfiqar opened 11 months ago

mudassirzulfiqar commented 11 months ago

Describe the bug If you are in other VOIP calls like Microsoft Team & WhatsApp. You cannot hear a person through PJSIP call. On the other hand, if you use Zoiper client, you cannot hear in other VOIP calls so Zoiper takes over the calling power.

Lib version Current latest

*Configuration NA

Changes NA

Smartphone (please complete the following information):

Additional context Is there any way to route Audio calls to different routes, as in iOS using Call Kit you can control this easily, by selecting different VoIP calls and make any call active. How Microsoft team is taking over my VOIP call, but I cant. How Zoiper is taking over Microsoft Team and Team doesnt. Anyone know any insights about it?

aenonGit commented 11 months ago

I think what you are looking for is the "Request Audio Focus" feature. It is independent from the library and should be handled by the client app. Basically you have to request the audio focus and listen to its state and react accordingly (e.g. if you lose focus). You should read about the Android Audio Manager

mudassirzulfiqar commented 10 months ago

here is the complete explanation of the problem, I would appreciate you if you could look into it. https://stackoverflow.com/questions/77040240/pjsip-android-call-cannot-hear-while-having-other-voip-call?noredirect=1#comment135816998_77040240

aenonGit commented 10 months ago

Based on the API level you should request the audio focus differently. I don't see any problem here. A simple if should be enough

mudassirzulfiqar commented 10 months ago

@aenonGit I see another issue, If I end the Microsoft Teams call, I'm able to talk again, but the Speaker stops working, I use a blow code to activate the speaker normally. AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); audioManager.setSpeakerphoneOn(true); The call doesn't go back to the speaker, although the earpiece works fine.

mudassirzulfiqar commented 10 months ago

I updated the link above, I mistakenly shared the wrong link.

aenonGit commented 10 months ago

Same as before, without requesting audio focus and listening for its state audio will never work fine.

mudassirzulfiqar commented 10 months ago

Thanks for your answer @aenonGit I have discovered this library https://github.com/twilio/audioswitch. Maybe something is interesting for me. But still when I establish my call while having the team call using the below code. Microphone doesn't work. I have no idea how Microsoft is interrupting my call.

@SuppressLint("NewApi") fun buildRequest(audioFocusChangeListener: OnAudioFocusChangeListener): AudioFocusRequest { val playbackAttributes = AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION) .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH) .build() return AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT) .setAudioAttributes(playbackAttributes) .setAcceptsDelayedFocusGain(true) .setOnAudioFocusChangeListener(audioFocusChangeListener) .build() }