start static method
Starts recording and returns once simctl reports the first frame ("Recording started" on stderr), or throws BackendToolError on early exit or timeout.
Implementation
static Future<SimctlRecording> start({
required String udid,
required String path,
Duration startTimeout = const Duration(seconds: 5),
}) async {
final proc = await startHelper(
'screen-recording', 'xcrun', ['simctl', 'io', udid, 'recordVideo', '--codec=h264', '--force', path],
device: udid, owner: 'sim:$udid', life: HelperLife.attachment);
final started = Completer<DateTime>();
final err = StringBuffer();
proc.stderr.transform(const SystemEncoding().decoder).listen((chunk) {
err.write(chunk);
if (!started.isCompleted && chunk.contains('Recording started')) {
started.complete(DateTime.now());
}
});
unawaited(proc.exitCode.then((code) {
if (!started.isCompleted) {
started.completeError(BackendToolError(
backend: 'ios-sim($udid)',
command: 'simctl io recordVideo',
exitCode: code,
stderr: err.toString().trim(),
));
}
}));
final DateTime t0;
try {
t0 = await started.future.timeout(startTimeout);
} on TimeoutException {
proc.kill(ProcessSignal.sigkill);
throw BackendToolError(
backend: 'ios-sim($udid)',
command: 'simctl io recordVideo',
exitCode: -1,
stderr: 'recorder did not report "Recording started" within '
'${startTimeout.inSeconds}s: ${err.toString().trim()}',
);
}
return SimctlRecording._(proc, path, t0, 'ios-sim($udid)');
}