|
|
@@ -23,6 +23,7 @@ import '../../data/consts/error_code.dart';
|
|
|
import '../../data/consts/event_report_id.dart';
|
|
|
import '../../data/repositories/talk_repository.dart';
|
|
|
import '../../dialog/alert_dialog.dart';
|
|
|
+import '../../dialog/record_max_dialog.dart';
|
|
|
import '../../resource/string.gen.dart';
|
|
|
import '../../utils/http_handler.dart';
|
|
|
import '../../utils/mmkv_util.dart';
|
|
|
@@ -64,9 +65,8 @@ class RecordHandler {
|
|
|
String get lastRecordId => _lastRecordId ?? '';
|
|
|
StreamSubscription? _currentDurationListener;
|
|
|
StreamSubscription? _recordActionListener;
|
|
|
- final int maxRecordDuration = 60 * 60 * 5 - 60; //最大录音时长5小时,减去1分钟以防止录音时长超过5小时
|
|
|
- final int maxRecordSize =
|
|
|
- 1024 * 1024 * 1024 - 1024 * 1024; //最大录音文件1G,减去1M以防止录音文件超过1G
|
|
|
+ final int maxRecordDuration = 60 * 60 * 5; //最大录音时长5小时
|
|
|
+ final int maxRecordSize = 1024 * 1024 * 1024; //最大录音文件1G
|
|
|
int currentRecordSize = 0;
|
|
|
|
|
|
void init() {
|
|
|
@@ -275,24 +275,24 @@ class RecordHandler {
|
|
|
if (data.isEmpty) {
|
|
|
return;
|
|
|
}
|
|
|
- if (currentDuration.value >= maxRecordDuration) {
|
|
|
- ToastUtil.showToast("录音时长已达上限");
|
|
|
+ var nowTime = _getPcmDuration(
|
|
|
+ data.length, recordConfig.sampleRate, 16, recordConfig.numChannels);
|
|
|
+ if (currentDuration.value + nowTime >= maxRecordDuration) {
|
|
|
+ showRecordMaxDialog("录音时长已达上限", tag: "recordMaxDialog");
|
|
|
stopRecord();
|
|
|
return;
|
|
|
}
|
|
|
- if (currentRecordSize >= maxRecordSize) {
|
|
|
- ToastUtil.showToast("录音文件已达上限");
|
|
|
+ if (currentRecordSize + data.length >= maxRecordSize) {
|
|
|
+ showRecordMaxDialog("录音文件大小已达上限", tag: "recordMaxDialog");
|
|
|
stopRecord();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
targetFile.writeAsBytesSync(data, mode: FileMode.append);
|
|
|
currentRecordSize += data.length;
|
|
|
- currentDuration.value = currentDuration.value +
|
|
|
- _getPcmDuration(data.length, recordConfig.sampleRate, 16,
|
|
|
- recordConfig.numChannels);
|
|
|
+ currentDuration.value = currentDuration.value + nowTime;
|
|
|
debugPrint(
|
|
|
- "currentDuration: ${formatDuration(currentDuration.value)} , currentSize: ${currentRecordSize.toReadableSize()}");
|
|
|
+ "currentDuration: ${currentDuration.value} , currentSize: ${currentRecordSize.toReadableSize()}");
|
|
|
}, onDone: () {
|
|
|
_changeRecordStatus(RecordStatus.paused);
|
|
|
}, onError: (error) {
|
|
|
@@ -312,13 +312,6 @@ class RecordHandler {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- String formatDuration(double value) {
|
|
|
- int hour = (value / 3600).floor();
|
|
|
- int minute = ((value - hour * 3600) / 60).floor();
|
|
|
- int second = (value - hour * 3600 - minute * 60).floor();
|
|
|
- return '${hour.toString().padLeft(2, '0')}:${minute.toString().padLeft(2, '0')}:${second.toString().padLeft(2, '0')}';
|
|
|
- }
|
|
|
-
|
|
|
Future<void> _requestForegroundTaskPermission() async {
|
|
|
final NotificationPermission notificationPermission =
|
|
|
await FlutterForegroundTask.checkNotificationPermission();
|