Android中实现蓝牙录放音

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

环境:Android4.2.2

基层应用:SoundRecorder


蓝牙一般有两种语音相关的模式是A2DPSCO,前者是高质量音乐播放(俗称:只进不出),后者是语音通话(俗称:有进有出)。要实现语音从蓝牙进,那么它一字得处于SCO模式下,也是通话模式下。另外是一个问题是如果使用MediaPlayer播放音乐,会被重新切回到A2DP模式下,那么就会模式错乱。所以使用AudioPlayer是一个不错的选择。总体的工作有两个调整模式,使用AudioPlayer播放音频。就可以实现同时从蓝牙音频进出了。

输出到蓝牙耳机:AudioManager mAm = ( AudioManager ) getSystemService(Context.AUDIO_SERVICE);mAm.setMode(AudioManager.MODE_IN_CALL);mAm.setBluetoothScoOn(true);mAm.startBluetoothSco();

从蓝牙耳机输入

再次整理需求:

1.入口:蓝牙连接状态android HEADSET onServiceConnected

状态改变(只更改 配置文件 不会发送状态改变广播) ->

根据蓝牙名字或者MAC地址以及是否支持sco需要处理

->

连接上:开启录放

断开:关闭录放

只监听SCO:

AndroidManifest.xml

android.bluetooth.headset.profile.action.CONNECTION_STATE_CHANGED

BTBroadcastReceiver.java

private int mBluetoothHeadsetState = 0;@Overridepublic void onReceive(Context context, Intent intent) {    mContext = context;    Log.e(LOG_TAG, "BT connect changed!");    if (intent.getAction().equals(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED)) {        mBluetoothHeadsetState = intent.getIntExtra(BluetoothHeadset.EXTRA_STATE,                BluetoothHeadset.STATE_DISCONNECTED);        Log.d(LOG_TAG, "==> new state: " + mBluetoothHeadsetState);        updateBluetoothIndication();  // Also update any visible UI if necessary    }}public void updateBluetoothIndication() {    if (mBluetoothHeadsetState == BluetoothProfile.STATE_CONNECTED) {        Log.i(LOG_TAG, "BluetoothProfile.STATE_CONNECTED");    } else if (mBluetoothHeadsetState == BluetoothProfile.STATE_DISCONNECTING) {        Log.i(LOG_TAG, "BluetoothProfile.STATE_DISCONNECTING");    } else {        Log.i(LOG_TAG, "BluetoothProfile.OTHER");    }}


from packages/apps/Phone/src/com/android/phone/PhoneGlobals.java:1449

总合来说就是:切换蓝牙模式+Android边录边播应用 =BTScoPlayback

           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

这里写图片描述

猜你喜欢

转载自blog.csdn.net/hfyutdg/article/details/84026498