(180 ringning)No ringing tone while connecting call android pjsip (pjsua2)

2.4k views Asked by At

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

Everything is fine, but I am not hearing ringing sound when I am calling some one. But other end, he is receiving call.

Here, We can not judge that call is connecting to other one.

Please help me. Thank you.

3

There are 3 answers

2
manao On BEST ANSWER

Generate tone by yourself. You can use android.media.ToneGenerator. Something like this:

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

EDIT

You can get CallInfo in 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 for repeating tone you can use handler with postDelayed. Create helper class for this.

0
Nikhil Ranjan On

you can use Media player and play your custom tone in loop.

set AudioManager mode to MODE_IN_COMMUNICATION

1
AudioBubble On

The better way to do this is to use pjsua2 library. With this I mean to skip Android API and do as following:

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) { }

}