Feature Description
The addSimpleMsgListener
API is used to listen for and receive text and custom messages, with the callback defined in the V2TIMSimpleMsgListener
protocol.
The addAdvancedMsgListener
API is used to listen for and receive all types of messages (text, custom, and rich media messages), with the callback defined in the V2TIMAdvancedMsgListener
protocol.
Setting a Message Listener
The SDK provides the V2TIMSimpleMsgListener
simple message listener and the V2TIMAdvancedMsgListener
advanced message listener.
They differ in that:
1. The simple message listener can only receive text and custom messages. You can use it if your business only requires these two types of messages.
2. The advanced message listener can receive all types of messages. You can use it if your business also requires rich media, merged, and other messages.
Note:
1. addSimpleMsgListener
and addAdvancedMsgListener
are exclusive. Do not use both of them; otherwise, unpredictable logic bugs will occur.
2. A message listener must be added first to receive the following types of messages.
Simple message listener
Adding a listener
The receiver calls the addSimpleMsgListener
(Android / iOS and macOS / Windows) to add the simple message listener. We recommend it be called early, such as after the chat page is initialized, to ensure timely message receiving in the application. Sample code:
V2TIMManager.getInstance().addSimpleMsgListener(simpleMsgListener);
[[V2TIMManager sharedInstance] addSimpleMsgListener:self];
class SimpleMsgListener final : public V2TIMSimpleMsgListener {
};
SimpleMsgListener simpleMsgListener;
V2TIMManager::GetInstance()->AddSimpleMsgListener(&simpleMsgListener);
Listener callback event
After adding the simple message listener, the receiver can receive different types of messages in the callback of V2TIMSimpleMsgListener
(Android / iOS and macOS / Windows), as described below: public abstract class V2TIMSimpleMsgListener {
public void onRecvC2CTextMessage(String msgID, V2TIMUserInfo sender, String text) {}
public void onRecvC2CCustomMessage(String msgID, V2TIMUserInfo sender, byte[] customData) {}
public void onRecvGroupTextMessage(String msgID, String groupID, V2TIMGroupMemberInfo sender, String text) {}
public void onRecvGroupCustomMessage(String msgID, String groupID, V2TIMGroupMemberInfo sender, byte[] customData) {}
}
@protocol V2TIMSimpleMsgListener <NSObject>
@optional
- (void)onRecvC2CTextMessage:(NSString *)msgID sender:(V2TIMUserInfo *)info text:(NSString *)text;
- (void)onRecvC2CCustomMessage:(NSString *)msgID sender:(V2TIMUserInfo *)info customData:(NSData *)data;
- (void)onRecvGroupTextMessage:(NSString *)msgID groupID:(NSString *)groupID sender:(V2TIMGroupMemberInfo *)info text:(NSString *)text;
- (void)onRecvGroupCustomMessage:(NSString *)msgID groupID:(NSString *)groupID sender:(V2TIMGroupMemberInfo *)info customData:(NSData *)data;
@end
class SimpleMsgListener final : public V2TIMSimpleMsgListener {
public:
SimpleMsgListener() = default;
~SimpleMsgListener() override = default;
void OnRecvC2CTextMessage(const V2TIMString& msgID, const V2TIMUserFullInfo& sender,
const V2TIMString& text) override {}
void OnRecvC2CCustomMessage(const V2TIMString& msgID, const V2TIMUserFullInfo& sender,
const V2TIMBuffer& customData) override {}
void OnRecvGroupTextMessage(const V2TIMString& msgID, const V2TIMString& groupID,
const V2TIMGroupMemberFullInfo& sender, const V2TIMString& text) override {}
void OnRecvGroupCustomMessage(const V2TIMString& msgID, const V2TIMString& groupID,
const V2TIMGroupMemberFullInfo& sender,
const V2TIMBuffer& customData) override {}
};
Removing a listener
To stop receiving messages, the receiver can call removeSimpleMsgListener
(Android / iOS and macOS / Windows) to remove the simple message listener. Sample code:
V2TIMManager.getInstance().removeSimpleMsgListener(simpleMsgListener);
[[V2TIMManager sharedInstance] removeSimpleMsgListener:self];
class SimpleMsgListener final : public V2TIMSimpleMsgListener {
};
V2TIMManager::GetInstance()->RemoveSimpleMsgListener(&simpleMsgListener);
Advanced message listener
Adding a listener
The receiver calls the addAdvancedMsgListener
(Android / iOS and macOS / Windows) to add the advanced message listener. We recommend it be called early, such as after the chat page is initialized, to ensure timely message receiving in the application. Sample code:
V2TIMManager.getMessageManager().addAdvancedMsgListener(advancedMsgListener);
[[V2TIMManager sharedInstance] addAdvancedMsgListener:self];
class AdvancedMsgListener final : public V2TIMAdvancedMsgListener {
};
AdvancedMsgListener advancedMsgListener;
V2TIMManager::GetInstance()->GetMessageManager()->AddAdvancedMsgListener(&advancedMsgListener);
Listener callback event
After adding the advanced message listener, the receiver can receive different types of messages in the callback of V2TIMAdvancedMsgListener
(Android / iOS and macOS / Windows), as described below: public abstract class V2TIMAdvancedMsgListener {
public void onRecvNewMessage(V2TIMMessage msg) {}
public void onRecvC2CReadReceipt(List<V2TIMMessageReceipt> receiptList) {}
public void onRecvMessageReadReceipts(List<V2TIMMessageReceipt> receiptList) {}
public void onRecvMessageRevoked(String msgID) {}
public void onRecvMessageModified(V2TIMMessage msg) {}
}
@protocol V2TIMAdvancedMsgListener <NSObject>
@optional
- (void)onRecvNewMessage:(V2TIMMessage *)msg;
- (void)onRecvMessageReadReceipts:(NSArray<V2TIMMessageReceipt *> *)receiptList;
- (void)onRecvC2CReadReceipt:(NSArray<V2TIMMessageReceipt *> *)receiptList;
- (void)onRecvMessageRevoked:(NSString *)msgID;
- (void)onRecvMessageModified:(V2TIMMessage *)msg;
@end
class AdvancedMsgListener final : public V2TIMAdvancedMsgListener {
public:
AdvancedMsgListener() = default;
~AdvancedMsgListener() override = default;
void OnRecvNewMessage(const V2TIMMessage& message) override {}
void OnRecvC2CReadReceipt(const V2TIMMessageReceiptVector& receiptList) override {}
void OnRecvMessageReadReceipts(const V2TIMMessageReceiptVector& receiptList) override {}
void OnRecvMessageRevoked(const V2TIMString& messageID) override {}
void OnRecvMessageModified(const V2TIMMessage& message) override {}
};
Removing a listener
To stop receiving messages, the receiver can call removeAdvancedMsgListener
(Android / iOS and macOS / Windows) to remove the advanced message listener. Sample code:
V2TIMManager.getMessageManager().removeAdvancedMsgListener(advancedMsgListener);
[[V2TIMManager sharedInstance] removeAdvancedMsgListener:self];
class AdvancedMsgListener final : public V2TIMAdvancedMsgListener {
};
V2TIMManager::GetInstance()->GetMessageManager()->RemoveAdvancedMsgListener(&advancedMsgListener);
Receiving a Text Message
Using simple message listener
One-to-one text message
The receiver can receive a one-to-one text message by using the simple message listener in the following steps:
1. Call addSimpleMsgListener
to set the event listener.
3. To stop receiving messages, call removeSimpleMsgListener
to remove the listener. This step is optional and can be performed as needed.
Sample code:
V2TIMManager.getInstance().addSimpleMsgListener(simpleMsgListener);
public void onRecvC2CTextMessage(String msgID, V2TIMUserInfo sender, String text) {
}
[[V2TIMManager sharedInstance] addSimpleMsgListener:self];
- (void)onRecvC2CTextMessage:(NSString *)msgID sender:(V2TIMUserInfo *)info text:(NSString *)text {
}
class SimpleMsgListener final : public V2TIMSimpleMsgListener {
public:
void OnRecvC2CTextMessage(const V2TIMString& msgID, const V2TIMUserFullInfo& sender,
const V2TIMString& text) override {
std::cout << "text:" << std::string{text.CString(), text.Size()} << std::endl;
}
};
SimpleMsgListener simpleMsgListener;
V2TIMManager::GetInstance()->AddSimpleMsgListener(&simpleMsgListener);
Group text message
The receiver can receive a group text message by using the simple message listener in the following steps:
1. Call addSimpleMsgListener
to set the event listener.
3. To stop receiving messages, call removeSimpleMsgListener
to remove the listener. This step is optional and can be performed as needed.
Sample code:
V2TIMManager.getInstance().addSimpleMsgListener(simpleMsgListener);
public void onRecvGroupTextMessage(String msgID, String groupID, V2TIMGroupMemberInfo sender, String text) {
}
[[V2TIMManager sharedInstance] addSimpleMsgListener:self];
- (void)onRecvGroupTextMessage:(NSString *)msgID groupID:(NSString *)groupID sender:(V2TIMGroupMemberInfo *)info text:(NSString *)text {
}
class SimpleMsgListener final : public V2TIMSimpleMsgListener {
public:
void OnRecvGroupTextMessage(const V2TIMString& msgID, const V2TIMString& groupID,
const V2TIMGroupMemberFullInfo& sender, const V2TIMString& text) override {
std::cout << "text:" << std::string{text.CString(), text.Size()} << std::endl;
}
};
SimpleMsgListener simpleMsgListener;
V2TIMManager::GetInstance()->AddSimpleMsgListener(&simpleMsgListener);
Using advanced message listener
The receiver can receive a one-to-one or group text message by using the advanced message listener in the following steps:
1. Call addAdvancedMsgListener
to set the event listener.
3. To stop receiving messages, call removeAdvancedMsgListener
to remove the listener. This step is optional and can be performed as needed.
Sample code:
V2TIMManager.getMessageManager().addAdvancedMsgListener(advancedMsgListener);
public void onRecvNewMessage(V2TIMMessage msg) {
String groupID = msg.getGroupID();
String userID = msg.getUserID();
if (msg.getElemType() == V2TIMMessage.V2TIM_ELEM_TYPE_TEXT) {
V2TIMTextElem textElem = msg.getTextElem();
String text = textElem.getText();
Log.i("onRecvNewMessage", "text:" + text);
}
}
[[V2TIMManager sharedInstance] addAdvancedMsgListener:self];
- (void)onRecvNewMessage:(V2TIMMessage *)msg {
NSString *groupID = msg.groupID;
NSString *userID = msg.userID;
if (msg.elemType == V2TIM_ELEM_TYPE_TEXT) {
V2TIMTextElem *textElem = msg.textElem;
NSString *text = textElem.text;
NSLog(@"onRecvNewMessage, text: %@", text);
}
}
class AdvancedMsgListener final : public V2TIMAdvancedMsgListener {
public:
void OnRecvNewMessage(const V2TIMMessage& message) override {
V2TIMString groupID = message.groupID;
V2TIMString userID = message.userID;
if (message.elemList.Size() == 1) {
V2TIMElem* elem = message.elemList[0];
if (elem->elemType == V2TIMElemType::V2TIM_ELEM_TYPE_TEXT) {
auto textElem = static_cast<V2TIMTextElem*>(elem);
V2TIMString text = textElem->text;
std::cout << "text:" << std::string{text.CString(), text.Size()} << std::endl;
}
}
}
};
AdvancedMsgListener advancedMsgListener;
V2TIMManager::GetInstance()->GetMessageManager()->AddAdvancedMsgListener(&advancedMsgListener);
Receiving a Custom Message
Using simple message listener
Custom one-to-one message
The receiver can receive a custom one-to-one message by using the simple message listener in the following steps:
1. Call addSimpleMsgListener
to set the event listener.
3. To stop receiving messages, call removeSimpleMsgListener
to remove the listener. This step is optional and can be performed as needed.
Sample code:
public void onRecvC2CCustomMessage(String msgID, V2TIMUserInfo sender, byte[] customData) {
Log.i("onRecvC2CCustomMessage", "msgID:" + msgID + ", from:" + sender.getNickName() + ", content:" + new String(customData));
}
- (void)onRecvC2CCustomMessage:(NSString *)msgID sender:(V2TIMUserInfo *)info customData:(NSData *)data {
NSLog(@"onRecvC2CCustomMessage, msgID: %@, sender: %@, customData: %@", msgID, info, data);
}
class SimpleMsgListener final : public V2TIMSimpleMsgListener {
public:
void OnRecvC2CCustomMessage(const V2TIMString& msgID, const V2TIMUserFullInfo& sender,
const V2TIMBuffer& customData) override {
std::cout << "customData:"
<< std::string{reinterpret_cast<const char*>(customData.Data()), customData.Size()}
<< std::endl;
}
};
SimpleMsgListener simpleMsgListener;
V2TIMManager::GetInstance()->AddSimpleMsgListener(&simpleMsgListener);
Custom group message
The receiver can receive a custom group message by using the simple message listener in the following steps:
1. Call addSimpleMsgListener
to set the event listener.
3. To stop receiving messages, call removeSimpleMsgListener
to remove the listener. This step is optional and can be performed as needed.
public void onRecvGroupCustomMessage(String msgID, String groupID, V2TIMGroupMemberInfo sender, byte[] customData) {
Log.i("onRecvGroupCustomMessage", "msgID:" + msgID + ", groupID:" + groupID + ", from:" + sender.getNickName() + ", content:" + new String(customData));
}
- (void)onRecvGroupCustomMessage:(NSString *)msgID groupID:(NSString *)groupID sender:(V2TIMGroupMemberInfo *)info customData:(NSData *)data {
NSLog(@"onRecvGroupCustomMessage, msgID: %@, groupID: %@, sender: %@, customData: %@", msgID, groupID, info, data);
}
class SimpleMsgListener final : public V2TIMSimpleMsgListener {
public:
void OnRecvGroupCustomMessage(const V2TIMString& msgID, const V2TIMString& groupID,
const V2TIMGroupMemberFullInfo& sender,
const V2TIMBuffer& customData) override {
std::cout << "customData:"
<< std::string{reinterpret_cast<const char*>(customData.Data()), customData.Size()}
<< std::endl;
}
};
SimpleMsgListener simpleMsgListener;
V2TIMManager::GetInstance()->AddSimpleMsgListener(&simpleMsgListener);
Using advanced message listener
The receiver can receive a custom one-to-one or group message by using the advanced message listener in the following steps:
1. Call addAdvancedMsgListener
to set the event listener.
3. To stop receiving messages, call removeAdvancedMsgListener
to remove the listener. This step is optional and can be performed as needed.
Sample code:
V2TIMManager.getMessageManager().addAdvancedMsgListener(v2TIMAdvancedMsgListener);
public void onRecvNewMessage(V2TIMMessage msg) {
String groupID = msg.getGroupID();
String userID = msg.getUserID();
if (msg.getElemType() == V2TIMMessage.V2TIM_ELEM_TYPE_CUSTOM) {
V2TIMCustomElem customElem = msg.getCustomElem();
String data = new String(customElem.getData());
Log.i("onRecvNewMessage", "customData:" + data);
}
}
[[V2TIMManager sharedInstance] addAdvancedMsgListener:self];
- (void)onRecvNewMessage:(V2TIMMessage *)msg {
NSString *groupID = msg.groupID;
NSString *userID = msg.userID;
if (msg.elemType == V2TIM_ELEM_TYPE_CUSTOM) {
V2TIMCustomElem *customElem = msg.customElem;
NSData *customData = customElem.data;
NSLog(@"onRecvNewMessage, customData: %@", customData);
}
}
class AdvancedMsgListener final : public V2TIMAdvancedMsgListener {
public:
void OnRecvNewMessage(const V2TIMMessage& message) override {
V2TIMString groupID = message.groupID;
V2TIMString userID = message.userID;
if (message.elemList.Size() == 1) {
V2TIMElem* elem = message.elemList[0];
if (elem->elemType == V2TIMElemType::V2TIM_ELEM_TYPE_CUSTOM) {
auto customElem = static_cast<V2TIMCustomElem*>(elem);
V2TIMBuffer data = customElem->data;
std::cout << "data:"
<< std::string{reinterpret_cast<const char*>(data.Data()), data.Size()}
<< std::endl;
}
}
}
};
AdvancedMsgListener advancedMsgListener;
V2TIMManager::GetInstance()->GetMessageManager()->AddAdvancedMsgListener(&advancedMsgListener);
The receiver can receive a rich media message only by using the advanced message listener in the following steps:
1. Call the addAdvancedMsgListener
API to set the advanced message listener.
3. Parse the elemType
attribute in the V2TIMMessage
message and then parse the message again according to the type to get the specific content of the elements in the message.
4. To stop receiving messages, call removeAdvancedMsgListener
to remove the listener. This step is optional and can be performed as needed.
Image message
The image in an image message can be in three formats: original, large, and thumbnail. The latter two are automatically generated by the SDK during message sending and can be ignored.
Large image: A large image is an image obtained after the original image is proportionally compressed. After the compression, the height or width (whichever is shorter) is equal to 720 pixels.
Thumbnail: A thumbnail is an image obtained after the original image is proportionally compressed. After the compression, the height or width (whichever is shorter) is equal to 198 pixels.
After the image message is received, we recommend you call the SDK's downloadImage
(Android / iOS and macOS / Windows) to download the image and then render it to the UI layer. To avoid repeated download and save resources, we recommend you set the uuid
attribute value of the V2TIMImage
object to the image download path to identify the image.
The following sample code demonstrates how to parse the image content from V2TIMMessage
:
public void onRecvNewMessage(V2TIMMessage msg) {
if (msg.getElemType() == V2TIMMessage.V2TIM_ELEM_TYPE_IMAGE) {
V2TIMImageElem v2TIMImageElem = msg.getImageElem();
List<V2TIMImageElem.V2TIMImage> imageList = v2TIMImageElem.getImageList();
for (V2TIMImageElem.V2TIMImage v2TIMImage : imageList) {
String uuid = v2TIMImage.getUUID();
int imageType = v2TIMImage.getType();
int size = v2TIMImage.getSize();
int width = v2TIMImage.getWidth();
int height = v2TIMImage.getHeight();
String url = v2TIMImage.getUrl();
String imagePath = "/sdcard/im/image/" + "myUserID" + uuid;
File imageFile = new File(imagePath);
if (!imageFile.exists()) {
v2TIMImage.downloadImage(imagePath, new V2TIMDownloadCallback() {
@Override
public void onProgress(V2TIMElem.V2ProgressInfo progressInfo) {
}
@Override
public void onError(int code, String desc) {
}
@Override
public void onSuccess() {
}
});
} else {
}
}
}
}
- (void)onRecvNewMessage:(V2TIMMessage *)msg {
if (msg.elemType == V2TIM_ELEM_TYPE_IMAGE) {
V2TIMImageElem *imageElem = msg.imageElem;
NSArray<V2TIMImage *> *imageList = imageElem.imageList;
for (V2TIMImage *timImage in imageList) {
NSString *uuid = timImage.uuid;
V2TIMImageType type = timImage.type;
int size = timImage.size;
int width = timImage.width;
int height = timImage.height;
NSString * url = timImage.url;
NSString *imagePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat: @"testImage%@", timImage.uuid]];
if (![[NSFileManager defaultManager] fileExistsAtPath:imagePath]) {
[timImage downloadImage:imagePath progress:^(NSInteger curSize, NSInteger totalSize) {
NSLog(@"Image download progress: curSize: %lu,totalSize:%lu",curSize,totalSize);
} succ:^{
NSLog(@"Image downloaded");
} fail:^(int code, NSString *msg) {
NSLog(@"Failed to download the image: code: %d,msg:%@",code,msg);
}];
} else {
}
NSLog(@"Image information: uuid:%@, type:%ld, size:%d, width:%d, height:%d", uuid, (long)type, size, width, height);
}
}
}
class DownloadCallback final : public V2TIMDownloadCallback {
public:
using SuccessCallback = std::function<void()>;
using ErrorCallback = std::function<void(int, const V2TIMString&)>;
using DownLoadProgressCallback = std::function<void(uint64_t, uint64_t)>;
DownloadCallback() = default;
~DownloadCallback() override = default;
void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback,
DownLoadProgressCallback download_progress_callback) {
success_callback_ = std::move(success_callback);
error_callback_ = std::move(error_callback);
download_progress_callback_ = std::move(download_progress_callback);
}
void OnSuccess() override {
if (success_callback_) {
success_callback_();
}
}
void OnError(int error_code, const V2TIMString& error_message) override {
if (error_callback_) {
error_callback_(error_code, error_message);
}
}
void OnDownLoadProgress(uint64_t currentSize, uint64_t totalSize) override {
if (download_progress_callback_) {
download_progress_callback_(currentSize, totalSize);
}
}
private:
SuccessCallback success_callback_;
ErrorCallback error_callback_;
DownLoadProgressCallback download_progress_callback_;
};
class AdvancedMsgListener final : public V2TIMAdvancedMsgListener {
public:
void OnRecvNewMessage(const V2TIMMessage& message) override {
if (message.elemList.Size() == 1) {
V2TIMElem* elem = message.elemList[0];
if (elem->elemType == V2TIMElemType::V2TIM_ELEM_TYPE_IMAGE) {
auto imageElem = static_cast<V2TIMImageElem*>(elem);
V2TIMImageVector imageList = imageElem->imageList;
for (size_t i = 0; i < imageList.Size(); ++i) {
V2TIMImage& image = imageList[i];
V2TIMString uuid = image.uuid;
V2TIMImageType type = image.type;
uint64_t size = image.size;
uint32_t width = image.width;
uint32_t height = image.height;
V2TIMString url = image.url;
std::filesystem::path imagePath = u8"./File/Image/"s + uuid.CString();
if (!std::filesystem::exists(imagePath)) {
std::filesystem::create_directories(imagePath.parent_path());
auto callback = new DownloadCallback{};
callback->SetCallback(
[=]() {
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
delete callback;
},
[=](uint64_t currentSize, uint64_t totalSize) {
});
image.DownloadImage(imagePath.string().c_str(), callback);
} else {
}
}
}
}
}
};
AdvancedMsgListener advancedMsgListener;
V2TIMManager::GetInstance()->GetMessageManager()->AddAdvancedMsgListener(&advancedMsgListener);
V2TIMString url = image.url;
Video message
After a video message is received, a video preview is displayed on the chat page, and the video is played back after the user clicks the message.
Two steps are required:
To avoid repeated download and save resources, we recommend you set the videoUUID
attribute value of the V2TIMVideoElem
object to the video download path to identify the video.
The following sample code demonstrates how to parse the video content from V2TIMMessage
:
public void onRecvNewMessage(V2TIMMessage msg) {
if (msg.getElemType() == V2TIMMessage.V2TIM_ELEM_TYPE_VIDEO) {
V2TIMVideoElem v2TIMVideoElem = msg.getVideoElem();
String snapshotUUID = v2TIMVideoElem.getSnapshotUUID();
int snapshotSize = v2TIMVideoElem.getSnapshotSize();
int snapshotWidth = v2TIMVideoElem.getSnapshotWidth();
int snapshotHeight = v2TIMVideoElem.getSnapshotHeight();
String videoUUID = v2TIMVideoElem.getVideoUUID();
int videoSize = v2TIMVideoElem.getVideoSize();
int duration = v2TIMVideoElem.getDuration();
String snapshotPath = "/sdcard/im/snapshot/" + "myUserID" + snapshotUUID;
File snapshotFile = new File(snapshotPath);
if (!snapshotFile.exists()) {
v2TIMVideoElem.downloadSnapshot(snapshotPath, new V2TIMDownloadCallback() {
@Override
public void onProgress(V2TIMElem.V2ProgressInfo progressInfo) {
}
@Override
public void onError(int code, String desc) {
}
@Override
public void onSuccess() {
}
});
} else {
}
String videoPath = "/sdcard/im/video/" + "myUserID" + videoUUID;
File videoFile = new File(videoPath);
if (!videoFile.exists()) {
v2TIMVideoElem.downloadVideo(videoPath, new V2TIMDownloadCallback() {
@Override
public void onProgress(V2TIMElem.V2ProgressInfo progressInfo) {
}
@Override
public void onError(int code, String desc) {
}
@Override
public void onSuccess() {
}
});
} else {
}
}
}
- (void)onRecvNewMessage:(V2TIMMessage *)msg {
if (msg.elemType == V2TIM_ELEM_TYPE_VIDEO) {
V2TIMVideoElem *videoElem = msg.videoElem;
NSString *snapshotUUID = videoElem.snapshotUUID;
int snapshotSize = videoElem.snapshotSize;
int snapshotWidth = videoElem.snapshotWidth;
int snapshotHeight = videoElem.snapshotHeight;
NSString *videoUUID = videoElem.videoUUID;
int videoSize = videoElem.videoSize;
int duration = videoElem.duration;
NSString *snapshotPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat: @"testVideoSnapshot%@",snapshotUUID]];
if (![[NSFileManager defaultManager] fileExistsAtPath:snapshotPath]) {
[videoElem downloadSnapshot:snapshotPath progress:^(NSInteger curSize, NSInteger totalSize) {
NSLog(@"%@", [NSString stringWithFormat:@"Video screenshot download progress: curSize: %lu,totalSize:%lu",curSize,totalSize]);
} succ:^{
NSLog(@"Video screenshot downloaded");
} fail:^(int code, NSString *msg) {
NSLog(@"%@", [NSString stringWithFormat:@"Failed to download the video screenshot: code: %d,msg:%@",code,msg]);
}];
} else {
}
NSLog(@"Video screenshot information: snapshotUUID:%@, snapshotSize:%d, snapshotWidth:%d, snapshotWidth:%d, snapshotPath:%@", snapshotUUID, snapshotSize, snapshotWidth, snapshotHeight, snapshotPath);
NSString *videoPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat: @"testVideo%@",videoUUID]];
if (![[NSFileManager defaultManager] fileExistsAtPath:videoPath]) {
[videoElem downloadVideo:videoPath progress:^(NSInteger curSize, NSInteger totalSize) {