Started/stopped state of recording marked wrong
Closed this issue · 1 comments
Looks like the internal logic of the MicrophoneRecorder
prevents starting and stoping of the recorder multiple times over the same object. After some debugging I might have found the culprit for this: the copyWith method is setting wrong values.
Future<void> start() async {
...
assert(!value.started, 'The recorder can only be started once.');
...
}
this line will check if the recorder is already started by asserting the value.started value.
On stop though, we have this:
value = value.copyWith(
stopped: true,
recording: MicrophoneRecording(url: recording),
);
And the copyWith will assume the previous state of the started value (which in this case is true), so after stopping the object will look like this:
MicrophoneRecorderValue(started: true, stopped: true, recording: true)
for that reason the next time you execute recorder.start()
the first mentioned assertion will fail (as value.started will still be set to true).
There might be two solutions for this:
- Fix the copyWith so that in case of an null input value it does not default to
this.started
but rather tofalse
. - Make new instances of the
MicrophoneRecorderValue
instead of copying the originally created value.
Hope this helps.
Hi @abalalovski - thanks for using the package :)
The docs mention this as the first thing:
Note that a single recorder can only make a single recording. Simply create a new recorder if you want to make another recording. Further note that you can also record simultaneously.
So this is intended behavior.