1,新增录音中不播放锁发过来的声音逻辑
2,优化视频刷新页面的逻辑减少白屏
This commit is contained in:
parent
5b74ede9ac
commit
366daf69c5
@ -21,22 +21,6 @@ class LockMonitoringLogic extends BaseGetXController {
|
||||
state.voiceProcessor = VoiceProcessor.instance;
|
||||
}
|
||||
|
||||
/// 收到视频流数据
|
||||
StreamSubscription? _getTVDataRefreshUIEvent;
|
||||
void _getTVDataRefreshUIAction() {
|
||||
// 蓝牙协议通知传输跟蓝牙之外的数据传输类不一样 eventBus
|
||||
_getTVDataRefreshUIEvent =
|
||||
eventBus.on<GetTVDataRefreshUI>().listen((event) async {
|
||||
if (event.tvList.isNotEmpty) {
|
||||
// print('收到图片了啦啦啦啦啦啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊');
|
||||
// 预加载图片数据
|
||||
Uint8List imageData = Uint8List.fromList(event.tvList);
|
||||
// 更新状态
|
||||
state.listPhotoData.value = imageData;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// 收到UDP发送的状态
|
||||
StreamSubscription? _getUDPStatusRefreshUIEvent;
|
||||
void _getUDPStatusRefreshUIAction() {
|
||||
@ -164,6 +148,7 @@ class LockMonitoringLogic extends BaseGetXController {
|
||||
|
||||
//开始录音
|
||||
Future<void> startProcessing() async {
|
||||
CallTalk().finishPcmSound();
|
||||
state.isButtonDisabled.value = true;
|
||||
|
||||
state.voiceProcessor?.addFrameListener(_onFrame);
|
||||
@ -407,9 +392,7 @@ class LockMonitoringLogic extends BaseGetXController {
|
||||
void onReady() {
|
||||
// TODO: implement onReady
|
||||
super.onReady();
|
||||
print("onReady()");
|
||||
|
||||
_getTVDataRefreshUIAction();
|
||||
_getUDPStatusRefreshUIAction();
|
||||
|
||||
initRecorder();
|
||||
@ -425,10 +408,11 @@ class LockMonitoringLogic extends BaseGetXController {
|
||||
void onClose() {
|
||||
// TODO: implement onClose
|
||||
print("锁详情界面销毁了");
|
||||
CallTalk().stopPcmSound();
|
||||
CallTalk().finishPcmSound();
|
||||
stopProcessing();
|
||||
_getTVDataRefreshUIEvent!.cancel();
|
||||
_getUDPStatusRefreshUIEvent!.cancel();
|
||||
state.getTVDataRefreshUIEvent!.cancel();
|
||||
|
||||
if (state.oneMinuteTimeTimer != null) {
|
||||
state.oneMinuteTimeTimer.cancel();
|
||||
state.oneMinuteTime.value = 0;
|
||||
|
||||
@ -2,6 +2,7 @@ import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@ -11,6 +12,7 @@ import 'package:image_gallery_saver/image_gallery_saver.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:star_lock/talk/call/callTalk.dart';
|
||||
import 'package:star_lock/talk/udp/udp_manage.dart';
|
||||
import 'package:star_lock/tools/eventBusEventManage.dart';
|
||||
|
||||
import '../../../../app_settings/app_colors.dart';
|
||||
import '../../../../login/selectCountryRegion/common/index.dart';
|
||||
@ -32,6 +34,7 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
initAsync();
|
||||
_getTVDataRefreshUIAction();
|
||||
}
|
||||
|
||||
Future<void> initAsync() async {
|
||||
@ -50,23 +53,33 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
|
||||
// color: Colors.white,
|
||||
child: Stack(
|
||||
children: [
|
||||
Obx(() {
|
||||
if (state.listPhotoData.value.isEmpty ||
|
||||
state.listPhotoData.value.length < 10) {
|
||||
Image.memory(
|
||||
state.listPhotoData.value,
|
||||
gaplessPlayback: true,
|
||||
width: 1.sw,
|
||||
height: 1.sh,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return Container(color: Colors.transparent);
|
||||
} else {
|
||||
return Image.memory(
|
||||
state.listPhotoData.value,
|
||||
gaplessPlayback: true,
|
||||
width: 1.sw,
|
||||
height: 1.sh,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return Container(color: Colors.transparent);
|
||||
},
|
||||
);
|
||||
}
|
||||
}),
|
||||
},
|
||||
),
|
||||
// Obx(() {
|
||||
// if (state.listPhotoData.value.isEmpty ||
|
||||
// state.listPhotoData.value.length < 10) {
|
||||
// return Container(color: Colors.transparent);
|
||||
// } else {
|
||||
// return Image.memory(
|
||||
// state.listPhotoData.value,
|
||||
// gaplessPlayback: true,
|
||||
// width: 1.sw,
|
||||
// height: 1.sh,
|
||||
// fit: BoxFit.cover,
|
||||
// errorBuilder: (context, error, stackTrace) {
|
||||
// return Container(color: Colors.transparent);
|
||||
// },
|
||||
// );
|
||||
// }
|
||||
// }),
|
||||
Positioned(
|
||||
top: ScreenUtil().statusBarHeight + 30.h,
|
||||
width: 1.sw,
|
||||
@ -220,7 +233,7 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
|
||||
bottomBtnItemWidget(
|
||||
"images/main/icon_lockDetail_hangUp.png", "挂断", Colors.red, () async {
|
||||
logic.stopProcessing();
|
||||
CallTalk().stopPcmSound();
|
||||
CallTalk().finishPcmSound();
|
||||
// 挂断
|
||||
if (state.isClickHangUp.value == false) {
|
||||
logic.initiateUdpHangUpAction(3);
|
||||
@ -387,9 +400,40 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 收到视频流数据
|
||||
void _getTVDataRefreshUIAction() {
|
||||
// 蓝牙协议通知传输跟蓝牙之外的数据传输类不一样 eventBus
|
||||
state.getTVDataRefreshUIEvent =
|
||||
eventBus.on<GetTVDataRefreshUI>().listen((event) async {
|
||||
if (event.tvList.isNotEmpty && event.tvList.length > 100) {
|
||||
// 比较新旧数据是否相同
|
||||
Uint8List imageData = Uint8List.fromList(event.tvList);
|
||||
|
||||
if (!listEquals(state.listPhotoData.value, imageData)) {
|
||||
// 更新状态
|
||||
state.listPhotoData.value = imageData;
|
||||
// 设置标志为true,表示需要更新UI
|
||||
state.shouldUpdateUI.value = true;
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// print('addPostFrameCallback');
|
||||
// 调用setState方法之前检查标志,只有当标志为true时才更新UI
|
||||
if (state.shouldUpdateUI.value) {
|
||||
setState(() {
|
||||
// 更新UI
|
||||
});
|
||||
// 更新完UI后将标志重新设置为false
|
||||
state.shouldUpdateUI.value = false;
|
||||
}
|
||||
// });
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
logic.stopProcessing();
|
||||
state.getTVDataRefreshUIEvent!.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,6 +12,8 @@ class LockMonitoringState {
|
||||
var isOpenVoice = false.obs;
|
||||
int udpSendDataFrameNumber = 0; // 帧序号
|
||||
// var isSenderAudioData = false.obs;// 是否要发送音频数据
|
||||
StreamSubscription? getTVDataRefreshUIEvent; //收到视频流数据
|
||||
var shouldUpdateUI = false.obs; //是否需要更新UI
|
||||
|
||||
var userMobileIP = NetworkInfo().getWifiIP();
|
||||
var userUid = Storage.getUid();
|
||||
|
||||
@ -318,7 +318,7 @@ class RealTimePictureLogic extends BaseGetXController {
|
||||
void onClose() {
|
||||
// TODO: implement onClose
|
||||
print("锁详情界面销毁了");
|
||||
CallTalk().stopPcmSound();
|
||||
CallTalk().finishPcmSound();
|
||||
_getTVDataRefreshUIEvent!.cancel();
|
||||
_getUDPStatusRefreshUIEvent!.cancel();
|
||||
if (state.oneMinuteTimeTimer != null) {
|
||||
|
||||
@ -146,11 +146,12 @@ class CallTalk {
|
||||
}
|
||||
|
||||
//停止接收音频数据
|
||||
void stopPcmSound() {
|
||||
void finishPcmSound() {
|
||||
// FlutterPcmSound.setup(sampleRate: 8000, channelCount: 1);
|
||||
FlutterPcmSound.pause();
|
||||
FlutterPcmSound.clear();
|
||||
FlutterPcmSound.stop();
|
||||
print('已停止播放声音');
|
||||
|
||||
iframe = IframeInfo();
|
||||
iframe!.iframeIndex = 0;
|
||||
|
||||
@ -203,7 +203,7 @@ class CommandUDPReciverManager {
|
||||
break;
|
||||
case 30:
|
||||
{
|
||||
CallTalk().stopPcmSound();
|
||||
CallTalk().finishPcmSound();
|
||||
|
||||
// 监视结束
|
||||
if ((data[7] & 0x3) == 1) {
|
||||
|
||||
@ -188,7 +188,7 @@ class UDPTalkClass {
|
||||
isBeCall = false;
|
||||
// isEndCall = true;
|
||||
// LockMonitoringState().isClickHangUp.value = false;
|
||||
CallTalk().stopPcmSound();
|
||||
CallTalk().finishPcmSound();
|
||||
eventBus.fire(GetUDPStatusRefreshUI(UDPTalkClass().status));
|
||||
Get.back();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user