previewAudioTrim method
Live trim while a timeline handle is dragged; commit with saveState.
Trimming the head moves VideoEditorAudioTrack.projectStartTime with it, so the remaining audio stays where it was on the timeline.
Implementation
void previewAudioTrim(String id, {Duration? fileStart, Duration? fileEnd}) {
final index = audioTracks.indexWhere((a) => a.id == id);
if (index == -1) return;
final track = audioTracks[index];
final oldStart = track.startTime ?? Duration.zero;
final oldEnd = track.endTime ?? track.duration;
const minLength = Duration(milliseconds: 200);
var start = fileStart ?? oldStart;
var end = fileEnd ?? oldEnd;
if (start < Duration.zero) start = Duration.zero;
if (track.duration > Duration.zero && end > track.duration) end = track.duration;
if (end - start < minLength) {
if (fileStart != null) {
start = end - minLength;
} else {
end = start + minLength;
}
}
var projectStart = track.projectStartTime + (start - oldStart);
if (projectStart < Duration.zero) {
start -= projectStart;
projectStart = Duration.zero;
}
audioController.updateAudioTrim(id, start, end);
audioController.updateAudioPosition(id, projectStart);
notifyListeners();
}