Browse Source

实时数据解码发送到flutter层

newdev_shunjiawei
fdp 1 year ago
parent
commit
c0679752dc
  1. 21
      local_plugins/jieli/android/src/main/kotlin/com/yunqiinnovation/jieli/BleService.kt
  2. 1
      local_plugins/jieli/lib/jieli.dart
  3. 2
      local_plugins/jl_opus/android/src/main/kotlin/com/yunqiinnovation/jl_opus/JlOpusPlugin.kt

21
local_plugins/jieli/android/src/main/kotlin/com/yunqiinnovation/jieli/BleService.kt

@ -325,6 +325,13 @@ class BleService(private val context: Context) {
// 注册特征通知
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 {
Log.e(TAG, "未找到所需特征")
updateConnectionState(STATE_ERROR)
@ -349,14 +356,8 @@ class BleService(private val context: Context) {
characteristic: BluetoothGattCharacteristic
) {
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) {
// NOTIFY_CHAR_UUID -> {
// // 收到音频数据
@ -368,18 +369,16 @@ class BleService(private val context: Context) {
NOTIFY_CHAR_UUID -> {
// 处理控制消息
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)) {
// 处理设备返回的协议数据
fos?.write(value)
opusPlugin?.handleDecodeRequest(value)
//callback?.onAudioDataReceived(value)
}
// 判断是否是协议格式响应
if (value.isNotEmpty() && value[0].toInt() and 0xFF == 0xA5) {

1
local_plugins/jieli/lib/jieli.dart

@ -127,6 +127,7 @@ class Jieli {
break;
case EventType.audioData:
if (data is Uint8List) {
print('收到ble通道消息: $data');
_audioController.add(data);
}
break;

2
local_plugins/jl_opus/android/src/main/kotlin/com/yunqiinnovation/jl_opus/JlOpusPlugin.kt

@ -285,7 +285,7 @@ class JlOpusPlugin: FlutterPlugin, MethodCallHandler {
}
fun handleDecodeRequest(opusdata: ByteArray) {
Log.d(TAG, "handleDecodeRequest${opusdata}")
// Log.d(TAG, "handleDecodeRequest${opusdata}")
if (opusdata == null) {
return

Loading…
Cancel
Save