首页 > 编程知识 正文

android蓝牙耳机录音,android录麦克风声音

时间:2023-05-03 22:32:56 阅读:266675 作者:4779

olivierg基本上是对的(AudioSource仍然可以是MIC),一些基本的代码将如下所示:

am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

registerReceiver(new BroadcastReceiver() {

@Override

public void onReceive(Context context, Intent intent) {

int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, -1);

Log.d(TAG, "Audio SCO state: " + state);

if (AudioManager.SCO_AUDIO_STATE_CONNECTED == state) {

/*

* Now the connection has been established to the bluetooth device.

* Record audio or whatever (on another thread).With AudioRecord you can record with an object created like this:

* new AudioRecord(MediaRecorder.AudioSource.MIC, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO,

* AudioFormat.ENCODING_PCM_16BIT, audioBufferSize);

*

* After finishing, don't forget to unregister this receiver and

* to stop the bluetooth connection with am.stopBluetoothSco();

*/

unregisterReceiver(this);

}

}

}, new IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED));

Log.d(TAG, "starting bluetooth");

am.startBluetoothSco();

这个我再次偶然发现,我想指出,插槽评论的重要性包括正确的权限,最重要的是设置

在你的清单文件.没有它,您将不会收到任何错误信息,但状态将不会更改为连接.

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。