如何切换手机、手机扬声器、耳机或蓝牙设备的音频输出

Adi*_*a.K 5 audio android bluetooth android-audiomanager

我试图在我的应用程序中的不同源之间切换音频源。我们使用第三方视频库并使用 AudioManager 来播放声音。现在我们尝试有一个 UI 选项来在手机耳机、手机扬声器、耳机/蓝牙(是否已连接)之间的音频输出之间进行选择。就像我们在“电话呼叫”应用程序中看到的那样(当多个音频输出源可用时,电话、扬声器、蓝牙)。

Adi*_*a.K 2

Got it working:                                                                                                      'if(false) {
            //For BT
            mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
            mAudioManager.startBluetoothSco();
            mAudioManager.setBluetoothScoOn(true);
        } else if(true) {
            //For phone ear piece
            mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
            mAudioManager.stopBluetoothSco();
            mAudioManager.setBluetoothScoOn(false);
            mAudioManager.setSpeakerphoneOn(false);
        } else {
            //For phone speaker(loudspeaker)
            mAudioManager.setMode(AudioManager.MODE_NORMAL);
            mAudioManager.stopBluetoothSco();
            mAudioManager.setBluetoothScoOn(false);
            mAudioManager.setSpeakerphoneOn(true);
        }
Run Code Online (Sandbox Code Playgroud)