0

我按照 android 教程项目在我的应用程序中实现 openvidu,但是当我开始通话时,声音从听筒(如通话期间)而不是扬声器中发出。我可以修复它吗?

4

1 回答 1

0

你可以这样做:

//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);
        }
      }
    }

最重要的部分是这个,导入音频管理器:

import android.media.AudioManager;

然后:

AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
if (audioManager != null) {
            audioManager.setSpeakerphoneOn(true);
}
于 2020-04-08T09:24:58.030 回答