|
|
@ -325,6 +325,13 @@ class BleService(private val context: Context) { |
|
|
// 注册特征通知 |
|
|
// 注册特征通知 |
|
|
setupNotifications(gatt) |
|
|
setupNotifications(gatt) |
|
|
|
|
|
|
|
|
|
|
|
opusPlugin?.startOpusDecodeStream(false, 1, 16000, 40, object : |
|
|
|
|
|
JlOpusPlugin.Callback1 { |
|
|
|
|
|
override fun onAudioDataReceived1(pcmData: ByteArray) { |
|
|
|
|
|
// Log.i(TAG, "收到解码控制通知: ${pcmData.contentToString()}") |
|
|
|
|
|
callback?.onAudioDataReceived(pcmData) |
|
|
|
|
|
// 处理解码后的 PCM 数据(如播放或写入文件) |
|
|
|
|
|
}}) |
|
|
} else { |
|
|
} else { |
|
|
Log.e(TAG, "未找到所需特征") |
|
|
Log.e(TAG, "未找到所需特征") |
|
|
updateConnectionState(STATE_ERROR) |
|
|
updateConnectionState(STATE_ERROR) |
|
|
@ -349,14 +356,8 @@ class BleService(private val context: Context) { |
|
|
characteristic: BluetoothGattCharacteristic |
|
|
characteristic: BluetoothGattCharacteristic |
|
|
) { |
|
|
) { |
|
|
val characteristicUuid = characteristic.uuid.toString() |
|
|
val characteristicUuid = characteristic.uuid.toString() |
|
|
Log.d(TAG, "收到特征变化通知: $characteristicUuid") |
|
|
// Log.d(TAG, "收到特征变化通知: $characteristicUuid") |
|
|
|
|
|
|
|
|
opusPlugin?.startOpusDecodeStream(false, 1, 16000, 40, object : |
|
|
|
|
|
JlOpusPlugin.Callback1 { |
|
|
|
|
|
override fun onAudioDataReceived1(pcmData: ByteArray) { |
|
|
|
|
|
Log.i(TAG, "收到解码控制通知: ${pcmData.contentToString()}") |
|
|
|
|
|
// 处理解码后的 PCM 数据(如播放或写入文件) |
|
|
|
|
|
}}) |
|
|
|
|
|
when (characteristicUuid) { |
|
|
when (characteristicUuid) { |
|
|
// NOTIFY_CHAR_UUID -> { |
|
|
// NOTIFY_CHAR_UUID -> { |
|
|
// // 收到音频数据 |
|
|
// // 收到音频数据 |
|
|
@ -368,18 +369,16 @@ class BleService(private val context: Context) { |
|
|
NOTIFY_CHAR_UUID -> { |
|
|
NOTIFY_CHAR_UUID -> { |
|
|
// 处理控制消息 |
|
|
// 处理控制消息 |
|
|
val value = characteristic.value |
|
|
val value = characteristic.value |
|
|
Log.i(TAG, "收到控制通知: ${value.contentToString()}") |
|
|
// Log.i(TAG, "收到控制通知: ${value.size}") |
|
|
|
|
|
|
|
|
// 判断是否收到音频数据 |
|
|
// 判断是否收到音频数据 |
|
|
if (value.isNotEmpty() && (value[0].toInt() and 0xFF == 0x4b || value[0].toInt() and 0xFF == 0x48)) { |
|
|
if (value.isNotEmpty() && (value[0].toInt() and 0xFF == 0x4b || value[0].toInt() and 0xFF == 0x48)) { |
|
|
// 处理设备返回的协议数据 |
|
|
// 处理设备返回的协议数据 |
|
|
fos?.write(value) |
|
|
fos?.write(value) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
opusPlugin?.handleDecodeRequest(value) |
|
|
opusPlugin?.handleDecodeRequest(value) |
|
|
|
|
|
|
|
|
//callback?.onAudioDataReceived(value) |
|
|
|
|
|
} |
|
|
} |
|
|
// 判断是否是协议格式响应 |
|
|
// 判断是否是协议格式响应 |
|
|
if (value.isNotEmpty() && value[0].toInt() and 0xFF == 0xA5) { |
|
|
if (value.isNotEmpty() && value[0].toInt() and 0xFF == 0xA5) { |
|
|
|