Dragoș Grumeza
Dragoș Grumeza

Reputation: 43

How to enable speaker in pjsip android app?

I am trying to use the speaker in my pjsip app, so I am using setOutputRoute:

pjmedia_aud_dev_route route=pjmedia_aud_dev_route.PJMEDIA_AUD_DEV_ROUTE_LOUDSPEAKER; MyApp.ep.audDevManager().setOutputRoute(route, true);

but I am getting an error: invalid or unsupported audio capability (PJMEDIA_EAUD_INVCAP).

In pjsua it says: This method is only valid if the device has PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE capability in AudioDevInfo.caps flags, otherwise Error will be thrown.

I am thinking maybe I have to set this flag... But I don't know how

Upvotes: 2

Views: 2274

Answers (2)

ade.se
ade.se

Reputation: 1704

Pjsip/Pjsua as of version 2.11 does not support changing the output route on Android that way, but if you always want the sound to be played back on the speaker, and as a media/music type stream, you can change the stream type that PJSIP uses for all outgoing android audio.

To change it, you must modify the source used to compile PJSIP in this file;

pjmedia/src/pjmedia-audiodev/android_jni_dev.c

when creating the android audio track, change this:

0, /* STREAM_VOICE_CALL */

to this:

3, /* STREAM_MUSIC */

This will cause the audio to be played back as a media/music type audio and the system volume control for media/music will control the volume of it.

Upvotes: 0

oga
oga

Reputation: 490

I ran into the same problem some days ago. I know its not the answer, just an alternative but I ended up using this and it works good.

AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
audioManager.setSpeakerphoneOn(true);

I used the Android AudioManger to toggle between the Earpiece and the Speaker by calling setSpeakerOn(). If you use it be aware that if you toggle the output its set permanently corresponding to the context. You can get the current state by calling audioManager.isSpeakerphoneOn().

Upvotes: 4

Related Questions