如何从电话,电话扬声器,耳机或蓝牙设备切换音频输出 [英] How to switch audio output from Phone, Phone Speaker, earphones or Bluetooth device

查看:284
本文介绍了如何从电话,电话扬声器,耳机或蓝牙设备切换音频输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的应用中的不同来源之间切换音频来源.我们使用第三方视频库,并使用AudioManager播放声音.现在,我们尝试使用UI选项在手机听筒,手机扬声器,耳机/蓝牙(已连接)之间进行音频输出之间进行选择. 就像我们在电话"应用中看到的一样(当有多个音频输出源可用时,电话,扬声器,蓝牙).

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).

推荐答案

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

这篇关于如何从电话,电话扬声器,耳机或蓝牙设备切换音频输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆