How to switch audio output from Phone, Phone Speaker, earphones or Bluetooth device

徘徊边缘 提交于 2020-02-03 23:38:52

问题


Im trying to switch the audio source between different source in my app. We use a 3rd party Video Library and use AudioManager to play the sound. Now we are trying to have a UI option to select between audio output between Phone ear piece, Phone Speaker, Headphones/ Bluetooth (is any connected). Like we see in Phone Call app (when multiple audio output sources are available phone, speaker, bluetooth).


回答1:


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


来源:https://stackoverflow.com/questions/47057889/how-to-switch-audio-output-from-phone-phone-speaker-earphones-or-bluetooth-dev

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!