sendVideoMessage method

Future<void> sendVideoMessage(
  1. String path, {
  2. String? name,
  3. double? width,
  4. double? height,
  5. int? duration,
})

Implementation

Future<void> sendVideoMessage(
  String path, {
  String? name,
  double? width,
  double? height,
  int? duration,
}) async {
  if (path.isEmpty) {
    return;
  }
  final imageData = await VideoThumbnail.thumbnailData(
    video: path,
    imageFormat: ImageFormat.JPEG,
    maxWidth: 200,
    quality: 80,
  );
  if (imageData != null) {
    final directory = await getApplicationCacheDirectory();
    String thumbnailPath =
        '${directory.path}/thumbnail_${Random().nextInt(999999999)}.jpeg';
    final file = File(thumbnailPath);
    file.writeAsBytesSync(imageData);

    final videoFile = File(path);

    Image.file(file)
        .image
        .resolve(const ImageConfiguration())
        .addListener(ImageStreamListener((info, synchronousCall) {
      final msg = Message.createVideoSendMessage(
        targetId: profile.id,
        chatType: chatType,
        filePath: path,
        thumbnailLocalPath: file.path,
        width: info.image.width.toDouble(),
        height: info.image.height.toDouble(),
        fileSize: videoFile.lengthSync(),
        displayName: videoFile.path.split('/').last,
      );
      sendMessage(msg);
    }));
  }
}