createVideoMessage static method
Future<V2TimValueCallback<V2TimMsgCreateInfoResult>>
createVideoMessage(
{ - required String videoFilePath,
- required String type,
- required int duration,
- required String snapshotPath,
- dynamic inputElement,
})
Implementation
static Future<V2TimValueCallback<V2TimMsgCreateInfoResult>> createVideoMessage({
required String videoFilePath,
required String type,
required int duration,
required String snapshotPath,
dynamic inputElement,
}) async {
int? videosize = 0;
int? snapsize = 0;
if (videoFilePath.isNotEmpty) {
File video = File(videoFilePath);
if (video.existsSync()) {
videosize = (video.readAsBytesSync().length / 1024).ceil();
} else {
print("$videoFilePath is not exist . please check and try again.");
}
}
if (snapshotPath.isNotEmpty) {
File snap = File(snapshotPath);
if (snap.existsSync()) {
snapsize = (snap.readAsBytesSync().length / 1024).ceil();
} else {
print("$snapshotPath is not exist . please check and try again.");
}
}
print("videosize $videosize,snapsize $snapsize");
Map<String, dynamic> message = Tools.createNativeMessage(
elem: List<Map<String, dynamic>>.from([
Map<String, dynamic>.from({
"elem_type": Tools.dartElemTypeToNative(MessageElemType.V2TIM_ELEM_TYPE_VIDEO),
"video_elem_video_type": type,
"video_elem_video_size": videosize,
"video_elem_video_duration": duration,
"video_elem_video_path": videoFilePath,
"video_elem_image_type": "jpg",
"video_elem_image_size": snapsize,
"video_elem_image_width": 0,
"video_elem_image_height": 0,
"video_elem_image_path": snapshotPath,
})
]),
);
String key = Tools.generateUniqueString();
createdMessage[key] = message;
return V2TimValueCallback<V2TimMsgCreateInfoResult>.fromJson({
"code": 0,
"desc": "success",
"data": Map<String, dynamic>.from({"id": key, "messageInfo": (await Tools.convertMessage2Dart(message)).toJson()})
});
}