对讲挂断,结束音频

This commit is contained in:
Daisy 2024-01-06 14:49:44 +08:00
parent 6f9b26a19f
commit d9c76d8708
6 changed files with 91 additions and 93 deletions

View File

@ -6,6 +6,7 @@ import 'package:flutter_voice_processor/flutter_voice_processor.dart';
import 'package:get/get.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:star_lock/main/lockDetail/lockDetail/realTimePicture/realTimePicture_state.dart';
import 'package:star_lock/talk/call/callTalk.dart';
import '../../../../talk/call/g711.dart';
import '../../../../talk/udp/udp_manage.dart';
@ -62,6 +63,7 @@ class RealTimePictureLogic extends BaseGetXController {
userMobile: await state.userMobile,
userMobileIP: await state.userMobileIP,
endData: []);
CallTalk().stopPcmSound();
//
Get.back();

View File

@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:star_lock/main/lockDetail/lockDetail/realTimePicture/realTimePicture_logic.dart';
import 'package:star_lock/talk/call/callTalk.dart';
import '../../../../app_settings/app_colors.dart';
import '../../../../tools/showTFView.dart';
@ -193,7 +194,7 @@ class _RealTimePicturePageState extends State<RealTimePicturePage>
bottomBtnItemWidget(
"images/main/icon_lockDetail_hangUp.png", "挂断", Colors.red, () async {
logic.stopProcessing();
CallTalk().stopPcmSound();
//
logic.udpHangUpAction();
}),

View File

@ -1,4 +1,3 @@
import 'dart:async';
import 'dart:convert';
import 'dart:math';
@ -7,6 +6,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_voice_processor/flutter_voice_processor.dart';
import 'package:get/get.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:star_lock/talk/call/callTalk.dart';
import '../../../../talk/call/g711.dart';
import '../../../../talk/udp/udp_manage.dart';
@ -41,14 +41,16 @@ class LockMonitoringLogic extends BaseGetXController {
/// UDP发送的状态
StreamSubscription? _getUDPStatusRefreshUIEvent;
void _getUDPStatusRefreshUIAction() {
_getUDPStatusRefreshUIEvent = eventBus.on<GetUDPStatusRefreshUI>().listen((event) {
_getUDPStatusRefreshUIEvent =
eventBus.on<GetUDPStatusRefreshUI>().listen((event) {
state.udpStatus.value = event.udpStatus;
if(state.udpStatus.value == 8){
if (state.udpStatus.value == 8) {
// 60
state.oneMinuteTimeTimer = Timer.periodic(const Duration(seconds:1), (Timer t) async {
state.oneMinuteTimeTimer =
Timer.periodic(const Duration(seconds: 1), (Timer t) async {
state.oneMinuteTime.value++;
// Get.log('state.oneMinuteTime.value:${state.oneMinuteTime.value}');
if(state.oneMinuteTime.value >= 60){
if (state.oneMinuteTime.value >= 60) {
// 60
state.oneMinuteTimeTimer.cancel();
state.oneMinuteTime.value = 0;
@ -63,6 +65,7 @@ class LockMonitoringLogic extends BaseGetXController {
userMobileIP: await state.userMobileIP,
endData: []);
CallTalk().stopPcmSound();
//
Get.back();
}
@ -81,8 +84,7 @@ class LockMonitoringLogic extends BaseGetXController {
lockIP: UDPManage().host,
userMobile: await state.userMobile,
userMobileIP: await state.userMobileIP,
endData: []
);
endData: []);
}
///
@ -128,7 +130,9 @@ class LockMonitoringLogic extends BaseGetXController {
while (start < audioData.length) {
// await Future.delayed(const Duration(milliseconds: 50));
int end = (start + length > audioData.length) ? audioData.length : start + length;
int end = (start + length > audioData.length)
? audioData.length
: start + length;
List<int> sublist = audioData.sublist(start, end);
sendRecordData({
"bytes": sublist,
@ -165,7 +169,9 @@ class LockMonitoringLogic extends BaseGetXController {
errorListener(VoiceProcessorException error) {
print("VoiceProcessorException: $error");
};
}
;
state.voiceProcessor?.addFrameListener(frameListener);
state.voiceProcessor?.addErrorListener(errorListener);
@ -173,15 +179,10 @@ class LockMonitoringLogic extends BaseGetXController {
if (await state.voiceProcessor?.hasRecordAudioPermission() ?? false) {
await state.voiceProcessor?.start(320, 8000);
bool? isRecording = await state.voiceProcessor?.isRecording();
} else {
}
} else {}
} on PlatformException catch (ex) {
Get.log("PlatformException: $ex");
} finally {
}
} finally {}
}
Future<void> stopProcessing() async {
@ -189,9 +190,7 @@ class LockMonitoringLogic extends BaseGetXController {
await state.voiceProcessor?.stop();
} on PlatformException catch (ex) {
Get.log("PlatformException: $ex");
} finally {
}
} finally {}
}
void onError(Object e) {
@ -199,7 +198,6 @@ class LockMonitoringLogic extends BaseGetXController {
}
sendRecordData(Map<String, dynamic> args) async {
List<int> bytes = args["bytes"];
// int udpSendDataFrameNumber = args["udpSendDataFrameNumber"];
String? lockID = args["lockID"];
@ -218,7 +216,7 @@ class LockMonitoringLogic extends BaseGetXController {
// while(list.isNotEmpty) {
state.udpSendDataFrameNumber++;
if (state.udpSendDataFrameNumber >= 65536) state.udpSendDataFrameNumber=1;
if (state.udpSendDataFrameNumber >= 65536) state.udpSendDataFrameNumber = 1;
// 57
List<int> topBytes = [];
@ -281,7 +279,8 @@ class LockMonitoringLogic extends BaseGetXController {
topBytes[6] = (state.udpSendDataFrameNumber & 0x000000FF);
topBytes[7] = ((state.udpSendDataFrameNumber & 0x0000FF00) >> 8);
print("udpSendDataFrameNumber:${state.udpSendDataFrameNumber} topBytes[63]:${topBytes[6]} topBytes[64]:${topBytes[7]}");
print(
"udpSendDataFrameNumber:${state.udpSendDataFrameNumber} topBytes[63]:${topBytes[6]} topBytes[64]:${topBytes[7]}");
topBytes.addAll(bytes);
Get.log("setVoiceBytes:$topBytes");
@ -293,8 +292,7 @@ class LockMonitoringLogic extends BaseGetXController {
lockIP: lockIP,
userMobile: userMobile,
userMobileIP: userMobileIP,
endData: topBytes
);
endData: topBytes);
// UDPManage().sendData(topBytes);
}
@ -324,7 +322,16 @@ class LockMonitoringLogic extends BaseGetXController {
}
int search(int val) {
List<int> table = [0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF];
List<int> table = [
0xFF,
0x1FF,
0x3FF,
0x7FF,
0xFFF,
0x1FFF,
0x3FFF,
0x7FFF
];
int size = 8;
for (int i = 0; i < size; i++) {
if (val <= table[i]) {
@ -392,9 +399,10 @@ class LockMonitoringLogic extends BaseGetXController {
void onClose() {
// TODO: implement onClose
print("锁详情界面销毁了");
CallTalk().stopPcmSound();
_getTVDataRefreshUIEvent!.cancel();
_getUDPStatusRefreshUIEvent!.cancel();
if(state.oneMinuteTimeTimer != null){
if (state.oneMinuteTimeTimer != null) {
state.oneMinuteTimeTimer.cancel();
}
stopProcessing();

View File

@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:star_lock/talk/call/callTalk.dart';
import '../../../../app_settings/app_colors.dart';
import '../../../../talk/udp/udp_manage.dart';
@ -43,12 +43,15 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
top: ScreenUtil().statusBarHeight + 30.h,
width: 1.sw,
child: Obx(() {
var sec = (state.oneMinuteTime.value % 60).toString().padLeft(2,'0');
var min = (state.oneMinuteTime.value ~/ 60).toString().padLeft(2,'0');
var sec =
(state.oneMinuteTime.value % 60).toString().padLeft(2, '0');
var min =
(state.oneMinuteTime.value ~/ 60).toString().padLeft(2, '0');
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("$min:$sec", style: TextStyle(fontSize: 26.sp, color: Colors.white)),
Text("$min:$sec",
style: TextStyle(fontSize: 26.sp, color: Colors.white)),
// SizedBox(width: 30.w),
// GestureDetector(
// onTap: () {
@ -66,8 +69,7 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
// ),
// ),
// ),
]
);
]);
}),
),
Positioned(
@ -155,45 +157,44 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
Widget bottomBottomBtnWidget() {
return Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
//
Obx(() => bottomBtnItemWidget(getAnswerBtnImg(), getAnswerBtnName(), Colors.white, () async {
//
await logic.getPermissionStatus().then((value) async {
if (!value) {
return;
}
Obx(() => bottomBtnItemWidget(
getAnswerBtnImg(), getAnswerBtnName(), Colors.white, () async {
//
await logic.getPermissionStatus().then((value) async {
if (!value) {
return;
}
// state.isSenderAudioData.value = false;
print("发送接听了");
//
logic.udpAnswerAction();
});
},
longPress: (){
//
print("onLongPress");
state.listAudioData.value = <int>[];
if (state.udpStatus.value == 8) {
state.udpStatus.value = 9;
}
// logic.readG711Data();
logic.startProcessing();
},
longPressUp: () async {
//
print("onLongPressUp");
if (state.udpStatus.value == 9) {
state.udpStatus.value = 8;
}
// state.isSenderAudioData.value = false;
print("发送接听了");
//
logic.udpAnswerAction();
});
}, longPress: () {
//
print("onLongPress");
state.listAudioData.value = <int>[];
if (state.udpStatus.value == 8) {
state.udpStatus.value = 9;
}
)
),
bottomBtnItemWidget("images/main/icon_lockDetail_hangUp.png", "挂断", Colors.red, () async {
// logic.readG711Data();
logic.startProcessing();
}, longPressUp: () async {
//
print("onLongPressUp");
if (state.udpStatus.value == 9) {
state.udpStatus.value = 8;
}
})),
bottomBtnItemWidget(
"images/main/icon_lockDetail_hangUp.png", "挂断", Colors.red, () async {
logic.stopProcessing();
CallTalk().stopPcmSound();
//
logic.udpHangUpAction();
}),
bottomBtnItemWidget("images/main/icon_lockDetail_monitoringUnlock.png", "开锁", AppColors.mainColor, () {
bottomBtnItemWidget("images/main/icon_lockDetail_monitoringUnlock.png",
"开锁", AppColors.mainColor, () {
showDeletPasswordAlertDialog(context);
})
]);
@ -202,26 +203,28 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
String getAnswerBtnImg() {
switch (state.udpStatus.value) {
case 8:
return "images/main/icon_lockDetail_monitoringUnTalkback.png";
return "images/main/icon_lockDetail_monitoringUnTalkback.png";
case 9:
return "images/main/icon_lockDetail_monitoringTalkback.png";
return "images/main/icon_lockDetail_monitoringTalkback.png";
default:
return "images/main/icon_lockDetail_monitoringAnswerCalls.png";
return "images/main/icon_lockDetail_monitoringAnswerCalls.png";
}
}
String getAnswerBtnName() {
switch (state.udpStatus.value) {
case 8:
return "长按说话";
return "长按说话";
case 9:
return "松开发送";
return "松开发送";
default:
return "接听";
return "接听";
}
}
Widget bottomBtnItemWidget(String iconUrl, String name, Color backgroundColor, Function() onClick, {Function()? longPress, Function()? longPressUp}) {
Widget bottomBtnItemWidget(
String iconUrl, String name, Color backgroundColor, Function() onClick,
{Function()? longPress, Function()? longPressUp}) {
var wh = 80.w;
return GestureDetector(
onTap: onClick,
@ -285,6 +288,5 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
@override
void dispose() {
super.dispose();
}
}

View File

@ -153,6 +153,9 @@ class CallTalk {
//
void stopPcmSound() {
FlutterPcmSound.setup(sampleRate: 8000, channelCount: 1);
FlutterPcmSound.pause();
FlutterPcmSound.clear();
FlutterPcmSound.stop();
}
}

View File

@ -1,5 +1,4 @@
import 'dart:async';
import 'package:audioplayers/audioplayers.dart';
import 'package:fast_gbk/fast_gbk.dart';
import 'package:flutter/material.dart';
@ -71,11 +70,7 @@ class UDPTalkClass {
UDPManage().sendData(data);
});
// _getFirstFrameGoPushAction();
// Future.delayed(const Duration(seconds: 1), () {
//
Get.toNamed(Routers.lockMonitoringPage, arguments: {"lockId": "111"});
// });
Get.toNamed(Routers.lockMonitoringPage, arguments: {"lockId": "111"});
}
playLocalAudio();
@ -84,19 +79,6 @@ class UDPTalkClass {
}
}
void _getFirstFrameGoPushAction() {
// eventBus
StreamSubscription _GetFirstFrameGoPushEvent =
eventBus.on<GetFirstFrameGoPush>().listen((event) {
if (event.isFirstFrame == true) {
Future.delayed(const Duration(seconds: 1), () {
//
Get.toNamed(Routers.lockMonitoringPage, arguments: {"lockId": "111"});
});
}
});
}
// call的本人
Future<bool> isCallMe(List<int>? data) async {
final loginData = await Storage.getLoginData();