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; 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发送的状态 /// UDP发送的状态
StreamSubscription? _getUDPStatusRefreshUIEvent; StreamSubscription? _getUDPStatusRefreshUIEvent;
void _getUDPStatusRefreshUIAction() { void _getUDPStatusRefreshUIAction() {
@ -164,6 +148,7 @@ class LockMonitoringLogic extends BaseGetXController {
// //
Future<void> startProcessing() async { Future<void> startProcessing() async {
CallTalk().finishPcmSound();
state.isButtonDisabled.value = true; state.isButtonDisabled.value = true;
state.voiceProcessor?.addFrameListener(_onFrame); state.voiceProcessor?.addFrameListener(_onFrame);
@ -407,9 +392,7 @@ class LockMonitoringLogic extends BaseGetXController {
void onReady() { void onReady() {
// TODO: implement onReady // TODO: implement onReady
super.onReady(); super.onReady();
print("onReady()");
_getTVDataRefreshUIAction();
_getUDPStatusRefreshUIAction(); _getUDPStatusRefreshUIAction();
initRecorder(); initRecorder();
@ -425,10 +408,11 @@ class LockMonitoringLogic extends BaseGetXController {
void onClose() { void onClose() {
// TODO: implement onClose // TODO: implement onClose
print("锁详情界面销毁了"); print("锁详情界面销毁了");
CallTalk().stopPcmSound(); CallTalk().finishPcmSound();
stopProcessing(); stopProcessing();
_getTVDataRefreshUIEvent!.cancel();
_getUDPStatusRefreshUIEvent!.cancel(); _getUDPStatusRefreshUIEvent!.cancel();
state.getTVDataRefreshUIEvent!.cancel();
if (state.oneMinuteTimeTimer != null) { if (state.oneMinuteTimeTimer != null) {
state.oneMinuteTimeTimer.cancel(); state.oneMinuteTimeTimer.cancel();
state.oneMinuteTime.value = 0; state.oneMinuteTime.value = 0;

View File

@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:io'; import 'dart:io';
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/services.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:path_provider/path_provider.dart';
import 'package:star_lock/talk/call/callTalk.dart'; import 'package:star_lock/talk/call/callTalk.dart';
import 'package:star_lock/talk/udp/udp_manage.dart'; import 'package:star_lock/talk/udp/udp_manage.dart';
import 'package:star_lock/tools/eventBusEventManage.dart';
import '../../../../app_settings/app_colors.dart'; import '../../../../app_settings/app_colors.dart';
import '../../../../login/selectCountryRegion/common/index.dart'; import '../../../../login/selectCountryRegion/common/index.dart';
@ -32,6 +34,7 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
void initState() { void initState() {
super.initState(); super.initState();
initAsync(); initAsync();
_getTVDataRefreshUIAction();
} }
Future<void> initAsync() async { Future<void> initAsync() async {
@ -50,23 +53,33 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
// color: Colors.white, // color: Colors.white,
child: Stack( child: Stack(
children: [ children: [
Obx(() { Image.memory(
if (state.listPhotoData.value.isEmpty || state.listPhotoData.value,
state.listPhotoData.value.length < 10) { gaplessPlayback: true,
width: 1.sw,
height: 1.sh,
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) {
return Container(color: Colors.transparent); return Container(color: Colors.transparent);
} else { },
return Image.memory( ),
state.listPhotoData.value, // Obx(() {
gaplessPlayback: true, // if (state.listPhotoData.value.isEmpty ||
width: 1.sw, // state.listPhotoData.value.length < 10) {
height: 1.sh, // return Container(color: Colors.transparent);
fit: BoxFit.cover, // } else {
errorBuilder: (context, error, stackTrace) { // return Image.memory(
return Container(color: Colors.transparent); // state.listPhotoData.value,
}, // gaplessPlayback: true,
); // width: 1.sw,
} // height: 1.sh,
}), // fit: BoxFit.cover,
// errorBuilder: (context, error, stackTrace) {
// return Container(color: Colors.transparent);
// },
// );
// }
// }),
Positioned( Positioned(
top: ScreenUtil().statusBarHeight + 30.h, top: ScreenUtil().statusBarHeight + 30.h,
width: 1.sw, width: 1.sw,
@ -220,7 +233,7 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
bottomBtnItemWidget( bottomBtnItemWidget(
"images/main/icon_lockDetail_hangUp.png", "挂断", Colors.red, () async { "images/main/icon_lockDetail_hangUp.png", "挂断", Colors.red, () async {
logic.stopProcessing(); logic.stopProcessing();
CallTalk().stopPcmSound(); CallTalk().finishPcmSound();
// //
if (state.isClickHangUp.value == false) { if (state.isClickHangUp.value == false) {
logic.initiateUdpHangUpAction(3); 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 @override
void dispose() { void dispose() {
super.dispose(); super.dispose();
logic.stopProcessing(); logic.stopProcessing();
state.getTVDataRefreshUIEvent!.cancel();
} }
} }

View File

@ -12,6 +12,8 @@ class LockMonitoringState {
var isOpenVoice = false.obs; var isOpenVoice = false.obs;
int udpSendDataFrameNumber = 0; // int udpSendDataFrameNumber = 0; //
// var isSenderAudioData = false.obs;// // var isSenderAudioData = false.obs;//
StreamSubscription? getTVDataRefreshUIEvent; //
var shouldUpdateUI = false.obs; //UI
var userMobileIP = NetworkInfo().getWifiIP(); var userMobileIP = NetworkInfo().getWifiIP();
var userUid = Storage.getUid(); var userUid = Storage.getUid();

View File

@ -318,7 +318,7 @@ class RealTimePictureLogic extends BaseGetXController {
void onClose() { void onClose() {
// TODO: implement onClose // TODO: implement onClose
print("锁详情界面销毁了"); print("锁详情界面销毁了");
CallTalk().stopPcmSound(); CallTalk().finishPcmSound();
_getTVDataRefreshUIEvent!.cancel(); _getTVDataRefreshUIEvent!.cancel();
_getUDPStatusRefreshUIEvent!.cancel(); _getUDPStatusRefreshUIEvent!.cancel();
if (state.oneMinuteTimeTimer != null) { if (state.oneMinuteTimeTimer != null) {

View File

@ -146,11 +146,12 @@ class CallTalk {
} }
// //
void stopPcmSound() { void finishPcmSound() {
// FlutterPcmSound.setup(sampleRate: 8000, channelCount: 1); // FlutterPcmSound.setup(sampleRate: 8000, channelCount: 1);
FlutterPcmSound.pause(); FlutterPcmSound.pause();
FlutterPcmSound.clear(); FlutterPcmSound.clear();
FlutterPcmSound.stop(); FlutterPcmSound.stop();
print('已停止播放声音');
iframe = IframeInfo(); iframe = IframeInfo();
iframe!.iframeIndex = 0; iframe!.iframeIndex = 0;

View File

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

View File

@ -188,7 +188,7 @@ class UDPTalkClass {
isBeCall = false; isBeCall = false;
// isEndCall = true; // isEndCall = true;
// LockMonitoringState().isClickHangUp.value = false; // LockMonitoringState().isClickHangUp.value = false;
CallTalk().stopPcmSound(); CallTalk().finishPcmSound();
eventBus.fire(GetUDPStatusRefreshUI(UDPTalkClass().status)); eventBus.fire(GetUDPStatusRefreshUI(UDPTalkClass().status));
Get.back(); Get.back();