androidsinchandroid-sinch-api

App does not connect audio to headphones Sinch App to App (Android)


I created App to App Android Sinch Application. When user on call without headphone its working on speaker but if user connect headphone its not automatically connecting to headphone instead of that i need to manually mute speaker and its connecting to headphone. Please check the code i done.

private void enableSpeaker(boolean enable) {
        AudioController audioController = getSinchServiceInterface().getAudioController();
        if (enable)
            audioController.enableSpeaker();
        else
            audioController.disableSpeaker();
        switchVolume.setImageDrawable(ContextCompat.getDrawable(this, isSpeaker ? R.drawable.ic_speaker : R.drawable.ic_speaker_off));
    }

    private void setMuteUnmute() {
        AudioController audioController = getSinchServiceInterface().getAudioController();
        if (isMute) {
            audioController.mute();
            switchMic.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_mic_off));
        } else {
            audioController.unmute();
            switchMic.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_mic_on));

        }

    }


Solution

  • I think you enabled Speaker in your onCallEstablished method.

    Remove enableSpeaker() method from onCallEstablished method and add enableAutomaticAudioRouting() like below.

    For more details check sinch documentation Here

    @Override
    public void onCallEstablished(Call call)
    {
        AudioController audioController = getSinchServiceInterface().getAudioController();
        audioController.enableAutomaticAudioRouting(true, AudioController.UseSpeakerphone.SPEAKERPHONE_AUTO);        
    }