ensureVideoInitialized method
Lazily initialise the video controller and start looping playback. Safe to call multiple times — only the first invocation kicks off the load.
Implementation
Future<void> ensureVideoInitialized() async {
if (input is! VideoMedia || _videoInitStarted) return;
_videoInitStarted = true;
final ctrl = XVideoPlayerController.file(input.file);
videoController = ctrl;
try {
await ctrl.initialize();
await ctrl.setLooping(true);
await ctrl.setVolume(videoEdit.muted ? 0 : 1);
ctrl.addListener(_enforceTrimLoop);
// Telegram picker parity (TGMediaPickerGalleryVideoItemView
// setIsCurrent): only a MUTED video auto-plays; with sound the
// poster waits under the play disc until the user taps it.
if (videoEdit.muted) await ctrl.play();
} catch (_) {
// Leave the controller in its uninitialised state; the preview
// falls back to an empty container which keeps layout stable.
}
if (disposed) return;
notifyListeners();
}