write method
Writes one frame after all previously returned write futures complete.
Implementation
@override
Future<void> write(
AudioFrame frame, {
AudioCancellationToken? cancellationToken,
}) {
cancellationToken?.throwIfCancelled();
if (_writeFuture != null) {
return Future<void>.error(
StateError('WAV file writes must be issued sequentially.'),
);
}
if (_finishFuture != null ||
_abortRequested ||
_abortFuture != null ||
_status.isTerminal) {
return Future<void>.error(
StateError('The WAV file session no longer accepts frames.'),
);
}
late final Future<void> operation;
operation = _write(frame, cancellationToken).whenComplete(() {
if (identical(_writeFuture, operation)) {
_writeFuture = null;
}
});
_writeFuture = operation;
return operation;
}