initialize method
Attempts to open the given video File and load metadata about the video.
Update the trim position depending on the maxDuration param
Generate the default cover _selectedCover
Initialize minCrop & maxCrop values base on aspectRatio
Throw a VideoMinDurationError error if the minDuration is bigger than videoDuration, the error should be handled as such:
controller
.initialize()
.then((_) => setState(() {}))
.catchError((error) {
// NOTE : handle the error here
}, test: (e) => e is VideoMinDurationError);
Implementation
Future<void> initialize({double? aspectRatio}) async {
await _video.initialize();
if (minDuration > videoDuration) {
throw VideoMinDurationError(minDuration, videoDuration);
}
_video.addListener(_videoListener);
_video.setLooping(true);
// if no [maxDuration] param given, maxDuration is the videoDuration
maxDuration = maxDuration == Duration.zero ? videoDuration : maxDuration;
// Trim straight away when maxDuration is lower than video duration
if (maxDuration < videoDuration) {
updateTrim(
0.0, maxDuration.inMilliseconds / videoDuration.inMilliseconds);
} else {
_updateTrimRange();
}
cropAspectRatio(aspectRatio);
generateDefaultCoverThumbnail();
notifyListeners();
}