feat: Display amplitude

This commit is contained in:
Christian Pauly 2021-08-11 21:21:08 +02:00
parent ddba6c2ad6
commit 47bce19d4a

View File

@ -24,6 +24,7 @@ class _RecordingDialogState extends State<RecordingDialog> {
bool error = false; bool error = false;
String _recordedPath; String _recordedPath;
final _audioRecorder = Record(); final _audioRecorder = Record();
Amplitude _amplitude;
void startRecording() async { void startRecording() async {
try { try {
@ -41,8 +42,12 @@ class _RecordingDialogState extends State<RecordingDialog> {
path: _recordedPath, encoder: AudioEncoder.AAC); path: _recordedPath, encoder: AudioEncoder.AAC);
setState(() => _duration = Duration.zero); setState(() => _duration = Duration.zero);
_recorderSubscription?.cancel(); _recorderSubscription?.cancel();
_recorderSubscription = Timer.periodic(Duration(seconds: 1), _recorderSubscription = Timer.periodic(Duration(seconds: 1), (_) async {
(_) => setState(() => _duration += Duration(seconds: 1))); _amplitude = await _audioRecorder.getAmplitude();
setState(() {
_duration += Duration(seconds: 1);
});
});
} catch (e, s) { } catch (e, s) {
SentryController.captureException(e, s); SentryController.captureException(e, s);
setState(() => error = true); setState(() => error = true);
@ -66,8 +71,8 @@ class _RecordingDialogState extends State<RecordingDialog> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
const maxDecibalWidth = 64.0; const maxDecibalWidth = 64.0;
final decibalWidth = final decibalWidth = ((_amplitude.current / _amplitude.max) * 2) *
((_duration.inSeconds % 2) + 1) * (maxDecibalWidth / 4).toDouble(); (maxDecibalWidth / 4).toDouble();
final time = final time =
'${_duration.inMinutes.toString().padLeft(2, '0')}:${(_duration.inSeconds % 60).toString().padLeft(2, '0')}'; '${_duration.inMinutes.toString().padLeft(2, '0')}:${(_duration.inSeconds % 60).toString().padLeft(2, '0')}';