对讲挂断,结束音频

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

View File

@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:star_lock/main/lockDetail/lockDetail/realTimePicture/realTimePicture_logic.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 '../../../../app_settings/app_colors.dart';
import '../../../../tools/showTFView.dart'; import '../../../../tools/showTFView.dart';
@ -193,7 +194,7 @@ class _RealTimePicturePageState extends State<RealTimePicturePage>
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();
// //
logic.udpHangUpAction(); logic.udpHangUpAction();
}), }),

View File

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

View File

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

View File

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

View File

@ -1,5 +1,4 @@
import 'dart:async'; import 'dart:async';
import 'package:audioplayers/audioplayers.dart'; import 'package:audioplayers/audioplayers.dart';
import 'package:fast_gbk/fast_gbk.dart'; import 'package:fast_gbk/fast_gbk.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -71,11 +70,7 @@ class UDPTalkClass {
UDPManage().sendData(data); UDPManage().sendData(data);
}); });
// _getFirstFrameGoPushAction(); Get.toNamed(Routers.lockMonitoringPage, arguments: {"lockId": "111"});
// Future.delayed(const Duration(seconds: 1), () {
//
Get.toNamed(Routers.lockMonitoringPage, arguments: {"lockId": "111"});
// });
} }
playLocalAudio(); 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的本人 // call的本人
Future<bool> isCallMe(List<int>? data) async { Future<bool> isCallMe(List<int>? data) async {
final loginData = await Storage.getLoginData(); final loginData = await Storage.getLoginData();