(180 calls) No ringtone when connecting call android pjsip (pjsua2)

I implemented a project for VOIP using PJSIP (PJSUA2).

Everything is fine, but I do not hear a loud sound when I call someone. But the other end, he gets a call.

Here we cannot judge that the call connects to another.

Please help me. Thank.

+4
source share
2 answers

Create your own tone. You can use android.media.ToneGenerator. Something like that:

ToneGenerator toneGenerator = new ToneGenerator(AudioManager.STREAM_VOICE_CALL, 100);
toneGenerator.startTone(ToneGenerator.TONE_CDMA_NETWORK_USA_RINGBACK, 1000);

EDIT

You can get CallInfo at notifyCallState.

CallInfo ci = call.getInfo();
if (ci.getState() == pjsip_inv_state.PJSIP_INV_STATE_EARLY 
    && ci.getRole() == pjsip_role_e.PJSIP_ROLE_UAC 
    && ci.getLastReason().equals("Ringing")) {
     toneGeneratorHelper.startRingBack();
} else {
  toneGeneratorHelper.stopRingBack();
}

And to repeat the tone, you can use a handler with postDelayed. Create a helper class for this.

+5
source

- pjsua2. Android API :

import org.pjsip.pjsua2.ToneDesc;
import org.pjsip.pjsua2.ToneDescVector;

private ToneDesc toneDesc;
private org.pjsip.pjsua2.ToneGenerator toneGenerator;
private ToneDescVector toneDescVector;

public class RINGBACK_TONES {
        public final static int kSPRingbackFrequency1 = 440,
                kSPRingbackFrequency2 = 480,
                kSPRingbackOnDuration = 1000,
                kSPRingbackOffDuration = 4000,
                kSPRingbackCount = 1,
                kSPRingbackInterval = 4000;
    }

protected synchronized void startRingbackTone() {

        toneDesc = new ToneDesc();
        toneGenerator = new org.pjsip.pjsua2.ToneGenerator();
        toneDescVector = new ToneDescVector();

        toneDesc.setFreq1((short) RINGBACK_TONES.kSPRingbackFrequency1);
        toneDesc.setFreq2((short) RINGBACK_TONES.kSPRingbackFrequency2);
        toneDesc.setOn_msec((short) RINGBACK_TONES.kSPRingbackOnDuration);
        toneDesc.setOff_msec((short) RINGBACK_TONES.kSPRingbackOffDuration);

        toneDescVector.add(toneDesc);

        try {
            toneGenerator.createToneGenerator();
            toneGenerator.play(toneDescVector, true);
            toneGenerator.startTransmit(Endpoint.audDevManager().getPlaybackDevMedia());

        } catch (Exception ex) { }
}

protected synchronized void stopRingbackTone() {

    try {
        if (toneGenerator != null)
            toneGenerator.stop();
        toneGenerator = null;

    } catch (Exception ex) { }

}
0

All Articles