runWithBuffer method
Runs the clock with an audio buffer while the onTick
callback returns true.
You need to await the returned future to wait for the clock to stop.
Implementation
Future<void> runWithBuffer({
required AudioFrames frames,
required bool Function(AudioClock, AudioBuffer) onTick,
}) {
final completer = Completer<void>();
frames.acquireBuffer((buffer) {
start(
onTick: (clock) {
try {
if (!onTick(clock, buffer)) {
stop();
completer.complete();
}
} catch (e, stack) {
stop();
completer.completeError(e, stack);
}
},
);
});
return completer.future;
}