trimVideo method
Exports the trimmed range. Progress for jobId arrives on progress
while this is in flight.
Implementation
@override
Future<MediaInfo> trimVideo(VideoTrimRequest request, String jobId) async {
trims.add(request);
final error = nextTrimError;
if (error != null) {
nextTrimError = null;
throw error;
}
for (final tick in progressTicks) {
// Yield between ticks. A real export delivers progress over a channel,
// never in the same microtask as its result — emitting synchronously
// would let the result outrun the ticks and drop them.
await Future<void>.delayed(Duration.zero);
if (_cancelled.contains(jobId)) break;
_progress.add(TrimProgress(jobId, tick));
}
if (exportDuration > Duration.zero) {
await Future<void>.delayed(exportDuration);
}
// Let the last tick reach its listeners before the result completes and
// the editor tears the subscription down.
await Future<void>.delayed(Duration.zero);
if (_cancelled.remove(jobId)) {
throw PlatformException(
code: kMonolensCancelled,
message: 'Export cancelled',
);
}
final source = files[request.sourcePath] ?? defaultInfo(request.sourcePath);
return MediaInfo(
path: request.outputPath,
width: source.width,
height: source.height,
durationMs: request.endMs - request.startMs,
byteSize: 4096,
);
}