start method
Implementation
Future<void> start(
{required String toFilePath, required void Function(String? path, Duration? duration) onCompleteCallBack, int maxSeconds = 0}) async {
if (_delegate == null) {
return Future.error('未注册 delegate');
}
if (_isRecording) {
return Future.value();
}
try {
final didGrand = await _delegate!.checkGrant();
if (!didGrand) {
throw Exception('未获取录音权限');
}
_currentFilePath = toFilePath;
_onCompleteCallBack = onCompleteCallBack;
final didRecord = await _delegate!.start(toFilePath);
_timer?.cancel();
if (didRecord) {
duration = 0;
_timer?.cancel();
_timer = Timer.periodic(const Duration(seconds: 1), (timer) async {
duration += 1;
if (duration >= maxSeconds) {
await end();
} else {
notifyListeners();
}
});
}
_isRecording = didRecord;
YkRecorderConfig.instance._changeRecord(recording: didRecord);
} catch (e) {
// _delegate?.error("_start ${e.toString()}");
}
return Future.value();
}