Openvidu - Set videocall audio to speaker Android

360 views Asked by At

I followed the android tutorial project to implement openvidu in my app but when i start the call sound comes out from the earpiece (like during a call) and not from the speaker. Home can I fix It?

1

There are 1 answers

0
Kenan Begić On

you can do it like this:

//Import audio manager
import android.media.AudioManager;

public class MyVideoCallActivity extends AppCompatActivity {

    private AudioManager audioManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //.....SOME CODE

        //Start Video call method
        startVideoCall();
    }

    public void startVideoCall() {
        //Setup audio manager that will output sound to speaker
        audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
        if (audioManager != null) {
            audioManager.setSpeakerphoneOn(true);
        }       
//...OTHER CODE that set up other views and stuff
    }

    //Later onDestroy revert to defaults.
    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (audioManager != null) {
            audioManager.setSpeakerphoneOn(false);
        }
      }
    }

Most important part is this, Import audio manager:

import android.media.AudioManager;

Then:

AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
if (audioManager != null) {
            audioManager.setSpeakerphoneOn(true);
}