音频数据 解析播放
This commit is contained in:
parent
a461ae99df
commit
158c37a69e
@ -26,7 +26,7 @@ class CallTalk {
|
|||||||
IframeInfo? iframe; // 假设有这个成员变量
|
IframeInfo? iframe; // 假设有这个成员变量
|
||||||
var growableList;
|
var growableList;
|
||||||
LockMonitoringPage callOut = const LockMonitoringPage();
|
LockMonitoringPage callOut = const LockMonitoringPage();
|
||||||
late FlutterSoundPlayer _player;
|
FlutterSoundPlayer _audioPlayer = FlutterSoundPlayer();
|
||||||
|
|
||||||
CallTalk._init() {
|
CallTalk._init() {
|
||||||
iframe = IframeInfo();
|
iframe = IframeInfo();
|
||||||
@ -53,13 +53,12 @@ class CallTalk {
|
|||||||
// 音频数据
|
// 音频数据
|
||||||
if (bb[61] == 1) {
|
if (bb[61] == 1) {
|
||||||
// 如果是音频数据且状态符合条件
|
// 如果是音频数据且状态符合条件
|
||||||
_player = FlutterSoundPlayer();
|
|
||||||
_initPlayer();
|
|
||||||
|
|
||||||
// 解码
|
_initializeAudioPlayer();
|
||||||
Uint8List g711Data = G711Decoder().decodeG711uLaw(bb);
|
|
||||||
|
|
||||||
await _playAudio(g711Data);
|
// 用你的711音频数据替换这里的Uint8List
|
||||||
|
Uint8List rawData = G711Decoder().decodeG711uLaw(bb);
|
||||||
|
_playRawData(rawData);
|
||||||
}
|
}
|
||||||
// 视频数据
|
// 视频数据
|
||||||
else {
|
else {
|
||||||
@ -190,14 +189,18 @@ class CallTalk {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _initPlayer() async {
|
Future<void> _initializeAudioPlayer() async {
|
||||||
await _player.openPlayer();
|
await _audioPlayer.openPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _playAudio(Uint8List audioData) async {
|
Future<void> _playRawData(Uint8List rawData) async {
|
||||||
await _player.startPlayer(
|
await _audioPlayer.startPlayer(
|
||||||
fromDataBuffer: audioData,
|
fromDataBuffer: rawData,
|
||||||
codec: Codec.pcm16WAV,
|
codec: Codec.pcm16,
|
||||||
|
whenFinished: () {
|
||||||
|
// 播放完成时的回调
|
||||||
|
print("Playback finished");
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user