音频数据 解析播放
This commit is contained in:
parent
a461ae99df
commit
158c37a69e
@ -26,7 +26,7 @@ class CallTalk {
|
||||
IframeInfo? iframe; // 假设有这个成员变量
|
||||
var growableList;
|
||||
LockMonitoringPage callOut = const LockMonitoringPage();
|
||||
late FlutterSoundPlayer _player;
|
||||
FlutterSoundPlayer _audioPlayer = FlutterSoundPlayer();
|
||||
|
||||
CallTalk._init() {
|
||||
iframe = IframeInfo();
|
||||
@ -53,13 +53,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 {
|
||||
@ -190,14 +189,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