如何从电话,电话扬声器,耳机或蓝牙设备切换音频输出



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

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

最新更新