sendVideoMessage method
Implementation
Future<void> sendVideoMessage(
String path, {
String? name,
double? width,
double? height,
int? duration,
}) async {
if (await createThreadIfNotExits() == false) return;
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: thread!.threadId,
filePath: path,
thumbnailLocalPath: file.path,
width: info.image.width.toDouble(),
height: info.image.height.toDouble(),
fileSize: videoFile.lengthSync(),
);
sendMessage(msg);
}));
}
}