fromVideoPath static method
Implementation
static Future<VideoWithThumbnailModal> fromVideoPath(String path, BuildContext context)async{
int durationInSeconds = 0;
try{
customPrint('Checking the video player controller');
// showSnackbar('video logs 2.1: initializing controller',storeLogs: true);
VideoPlayerController controller = VideoPlayerController.file(File(path));
await controller.initialize();
// showSnackbar('video logs 2.2: controller initialized',storeLogs: true);
durationInSeconds = controller.value.duration.inSeconds;
// showSnackbar('video logs 2.3: fetched video call duration $durationInSeconds',storeLogs: true);
}catch(e){
customPrint('Could not add duration $e');
}
// Uint8List? uint8list = null;
String? thumbnailPath;
try{
// Uint8List? uint8list = null;
// showSnackbar('video logs 2.4: fetching video thumbnail',storeLogs: true);
Uint8List? uint8list = await VideoThumbnail.thumbnailData(
video: path,
imageFormat: ImageFormat.PNG,
maxWidth: 400,
// specify the width of the thumbnail, let the height auto-scaled to keep the source aspect ratio
maxHeight: 400,
quality: 50,
);
// showSnackbar('video logs 2.5: fetching video..fetched',storeLogs: true);
final tempDir = await getTemporaryDirectory();
// showSnackbar('video logs 2.6: storing in temp directory $tempDir',storeLogs: true);
File? thumbnail = await File(
'${tempDir.path}/${DateTime.now().millisecondsSinceEpoch}.png')
.create();
// showSnackbar('video logs 2.7: writing to file thumbnail',storeLogs: true);
await thumbnail.writeAsBytes(uint8list.toList());
thumbnailPath = thumbnail.path;
}catch(e){
showSnackbar(context:context,'Please wait!! $e');
// showSnackbar('video logs 2.8: Error occured $e',storeLogs: true);
customPrint('video logs 2.8: Error occured $e');
}
return VideoWithThumbnailModal(filePath: path, thumbnailPath: thumbnailPath, durationInSeconds: durationInSeconds);
}