|
|
@@ -52,7 +52,7 @@ class RecordController extends BaseController {
|
|
|
var currentRecordFile = await _getCurrentRecordFile();
|
|
|
var fileLength = currentRecordFile.lengthSync();
|
|
|
if (currentRecordFile.existsSync() && fileLength > 0) {
|
|
|
- currentStatus.value = RecordStatus.paused;
|
|
|
+ _changeRecordStatus(RecordStatus.paused);
|
|
|
currentDuration.value = await _getPcmDuration(
|
|
|
fileLength, recordConfig.sampleRate, 16, recordConfig.numChannels);
|
|
|
}
|
|
|
@@ -60,10 +60,10 @@ class RecordController extends BaseController {
|
|
|
|
|
|
void addShortcut() {}
|
|
|
|
|
|
- void onBackClick(BuildContext context) {
|
|
|
+ void onBackClick() {
|
|
|
if (currentStatus.value == RecordStatus.pending ||
|
|
|
currentStatus.value == RecordStatus.paused) {
|
|
|
- Navigator.pop(context);
|
|
|
+ Get.back();
|
|
|
} else {
|
|
|
EAAlertDialog.show(
|
|
|
title: "是否保存当前录音?",
|
|
|
@@ -75,7 +75,7 @@ class RecordController extends BaseController {
|
|
|
},
|
|
|
cancelOnTap: () {
|
|
|
EAAlertDialog.dismiss();
|
|
|
- Navigator.pop(context);
|
|
|
+ _stopRecord().then((_) => Get.back());
|
|
|
},
|
|
|
);
|
|
|
}
|
|
|
@@ -123,23 +123,23 @@ class RecordController extends BaseController {
|
|
|
}
|
|
|
File targetFile = await _getCurrentRecordFile();
|
|
|
Stream<Uint8List> recordStream = await record.startStream(recordConfig);
|
|
|
- currentStatus.value = RecordStatus.recording;
|
|
|
+ _changeRecordStatus(RecordStatus.recording);
|
|
|
recordStream.listen((data) async {
|
|
|
targetFile.writeAsBytesSync(data, mode: FileMode.append);
|
|
|
currentDuration.value = currentDuration.value +
|
|
|
await _getPcmDuration(data.length, recordConfig.sampleRate, 16,
|
|
|
recordConfig.numChannels);
|
|
|
}, onDone: () {
|
|
|
- currentStatus.value = RecordStatus.paused;
|
|
|
+ _changeRecordStatus(RecordStatus.paused);
|
|
|
}, onError: (error) {
|
|
|
- currentStatus.value = RecordStatus.paused;
|
|
|
+ _changeRecordStatus(RecordStatus.paused);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
_onRecordPermissionDenied() {}
|
|
|
|
|
|
Future<void> _stopRecord() {
|
|
|
- return record.stop().then((_) => currentStatus.value = RecordStatus.paused);
|
|
|
+ return record.stop().then((_) => _changeRecordStatus(RecordStatus.paused));
|
|
|
}
|
|
|
|
|
|
Future<File> _getCurrentRecordFile() async {
|
|
|
@@ -166,7 +166,7 @@ class RecordController extends BaseController {
|
|
|
}
|
|
|
}).then((_) {
|
|
|
currentDuration.value = 0;
|
|
|
- currentStatus.value = RecordStatus.pending;
|
|
|
+ _changeRecordStatus(RecordStatus.pending);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -191,6 +191,11 @@ class RecordController extends BaseController {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ void _changeRecordStatus(RecordStatus status) {
|
|
|
+ currentStatus.value = status;
|
|
|
+ status == RecordStatus.recording ? frameAnimationController.play() : null;
|
|
|
+ }
|
|
|
+
|
|
|
static Future<File> getRecordFile(String talkId) async {
|
|
|
Directory documentDir = await getApplicationDocumentsDirectory();
|
|
|
return File("${documentDir.path}/.atmob/record/$talkId.wav");
|