1,新增录音中不播放锁发过来的声音逻辑

2,优化视频刷新页面的逻辑减少白屏
This commit is contained in:
Daisy 2024-04-12 14:03:52 +08:00
parent 5b74ede9ac
commit 366daf69c5
7 changed files with 72 additions and 41 deletions

View File

@ -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;

View File

@ -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;
// trueUI
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();
}
}

View File

@ -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();

View File

@ -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) {

View File

@ -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;

View File

@ -203,7 +203,7 @@ class CommandUDPReciverManager {
break;
case 30:
{
CallTalk().stopPcmSound();
CallTalk().finishPcmSound();
//
if ((data[7] & 0x3) == 1) {

View File

@ -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();