|
|
|
@ -237,8 +237,21 @@ fun startAudioRecord(audioSourceType: AudioSourceType, callback: AudioDataCallba |
|
|
|
// 设置通话模式 - 这是关键! |
|
|
|
audioManager?.mode = AudioManager.MODE_IN_COMMUNICATION |
|
|
|
|
|
|
|
// 启用扬声器(如果需要外放) |
|
|
|
audioManager?.isSpeakerphoneOn = true |
|
|
|
// 检查是否有蓝牙音频设备连接 |
|
|
|
val isBluetoothConnected = audioManager?.isBluetoothA2dpOn == true |
|
|
|
|
|
|
|
// 只有在没有蓝牙设备连接时才启用扬声器 |
|
|
|
if (!isBluetoothConnected) { |
|
|
|
audioManager?.isSpeakerphoneOn = true |
|
|
|
|
|
|
|
Log.d("AudioMode", "未检测到蓝牙设备,启用扬声器") |
|
|
|
} else { |
|
|
|
audioManager?.isSpeakerphoneOn = false |
|
|
|
// 启用蓝牙SCO连接 |
|
|
|
audioManager?.isBluetoothScoOn = true |
|
|
|
audioManager?.startBluetoothSco() |
|
|
|
Log.d("AudioMode", "检测到蓝牙设备,使用蓝牙音频") |
|
|
|
} |
|
|
|
|
|
|
|
// 请求音频焦点 |
|
|
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { |
|
|
|
|