setVideoEdit method

void setVideoEdit(
  1. VideoEditValues next
)

Scrubber/mute write path: stores the values, applies volume immediately, and snaps the playhead into the trim range.

Implementation

void setVideoEdit(VideoEditValues next) {
  if (videoEdit == next) return;
  // A trim arrives continuously from a scrubber drag, which logs the
  // committed range once the gesture ends; mute, crop and overlay are
  // discrete edits that each deserve a record.
  final fields = <String, Object?>{
    'trimStartMs': next.trimStart?.inMilliseconds,
    'trimEndMs': next.trimEnd?.inMilliseconds,
    'muted': next.muted,
    'crop': next.crop != null,
    'overlay': next.overlay != null,
  };
  if (next.muted == videoEdit.muted &&
      next.crop == videoEdit.crop &&
      next.overlay == videoEdit.overlay) {
    _log.d('videoEdit', fields: fields);
  } else {
    _log.i('videoEdit', fields: fields);
  }
  videoEdit = next;
  final ctrl = videoController;
  if (ctrl != null && ctrl.value.isInitialized) {
    ctrl.setVolume(next.muted ? 0 : 1).unawaited();
    final start = next.trimStart ?? Duration.zero;
    final end = next.trimEnd;
    final pos = ctrl.value.position;
    if (pos < start || (end != null && pos > end)) {
      ctrl.seekTo(start).unawaited();
    }
  }
  notifyListeners();
}