1,新增录音中不播放锁发过来的声音逻辑
2,优化视频刷新页面的逻辑减少白屏
This commit is contained in:
parent
5b74ede9ac
commit
366daf69c5
@ -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;
|
||||||
|
|||||||
@ -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;
|
||||||
|
// 设置标志为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
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
logic.stopProcessing();
|
logic.stopProcessing();
|
||||||
|
state.getTVDataRefreshUIEvent!.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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();
|
||||||
|
|||||||
@ -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) {
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
@ -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) {
|
||||||
|
|||||||
@ -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();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user