generateThumbnailWithProgressHelper function

Future<File?> generateThumbnailWithProgressHelper(
  1. String url,
  2. void onProgress(
    1. double
    )
)

Implementation

Future<File?> generateThumbnailWithProgressHelper(String url, void Function(double) onProgress) async {
  File videoFile;
  if (Uri.parse(url).isAbsolute) {
    final tempDir = await getTemporaryDirectory();
    final filePath = "${tempDir.path}/${Uri.parse(url).pathSegments.last}";
    final file = File(filePath);
    final dio = Dio();
    await dio.download(
      url,
      filePath,
      onReceiveProgress: (received, total) {
        if (total != -1) {
          onProgress(received / total);
        }
      },
    );
    videoFile = file;
  } else {
    videoFile = File(url);
  }
  final XFile xfile = await VideoThumbnail.thumbnailFile(
    video: videoFile.path,
    thumbnailPath: (await getTemporaryDirectory()).path,
    maxHeight: 200,
    quality: 75,
  );
  return File(xfile.path);
}