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?
Asked
Active
Viewed 347 times
1 Answers
0
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);
}

Kenan Begić
- 1,228
- 11
- 21