711音频数据解析
This commit is contained in:
parent
4a131c88f5
commit
4f5e95ce00
@ -1,6 +1,8 @@
|
||||
import 'dart:typed_data';
|
||||
import 'package:convert/convert.dart';
|
||||
import 'package:flutter_sound/flutter_sound.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:star_lock/appRouters.dart';
|
||||
// import 'package:just_audio/just_audio.dart';
|
||||
import 'package:star_lock/main/lockDetail/monitoring/monitoring/lockMonitoring_page.dart';
|
||||
import 'package:star_lock/talk/call/g711Decoder.dart';
|
||||
@ -19,7 +21,7 @@ class CallTalk {
|
||||
int status = 0; // 假设有这个成员变量
|
||||
IframeInfo iframe = IframeInfo(); // 假设有这个成员变量
|
||||
LockMonitoringPage callOut = const LockMonitoringPage();
|
||||
late FlutterSoundPlayer _player;
|
||||
FlutterSoundPlayer _audioPlayer = FlutterSoundPlayer();
|
||||
|
||||
Future<void> getAVData(Uint8List bb, int len) async {
|
||||
//视频数据
|
||||
@ -34,13 +36,12 @@ class CallTalk {
|
||||
// 音频数据
|
||||
if (bb[61] == 1) {
|
||||
// 如果是音频数据且状态符合条件
|
||||
_player = FlutterSoundPlayer();
|
||||
_initPlayer();
|
||||
|
||||
// 解码
|
||||
Uint8List g711Data = G711Decoder().decodeG711uLaw(bb);
|
||||
_initializeAudioPlayer();
|
||||
|
||||
await _playAudio(g711Data);
|
||||
// 用你的711音频数据替换这里的Uint8List
|
||||
Uint8List rawData = G711Decoder().decodeG711uLaw(bb);
|
||||
_playRawData(rawData);
|
||||
}
|
||||
// 视频数据
|
||||
else {
|
||||
@ -74,6 +75,8 @@ class CallTalk {
|
||||
|
||||
Uint8List data = iframe.bb!.sublist(0, iframe.cur_len);
|
||||
|
||||
Get.toNamed(Routers.lockMonitoringPage,
|
||||
arguments: {"lockId": widget.lockListInfoItemEntity.lockId});
|
||||
// 打印拷贝后的目标数据
|
||||
print(iframe.bb);
|
||||
}
|
||||
@ -98,14 +101,18 @@ class CallTalk {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _initPlayer() async {
|
||||
await _player.openPlayer();
|
||||
Future<void> _initializeAudioPlayer() async {
|
||||
await _audioPlayer.openPlayer();
|
||||
}
|
||||
|
||||
Future<void> _playAudio(Uint8List audioData) async {
|
||||
await _player.startPlayer(
|
||||
fromDataBuffer: audioData,
|
||||
codec: Codec.pcm16WAV,
|
||||
Future<void> _playRawData(Uint8List rawData) async {
|
||||
await _audioPlayer.startPlayer(
|
||||
fromDataBuffer: rawData,
|
||||
codec: Codec.pcm16,
|
||||
whenFinished: () {
|
||||
// 播放完成时的回调
|
||||
print("Playback finished");
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user