Extension settings
- Login to CometChat and select your app.
- Go to Extensions section and enable the Thumbnail Generation extension.
How does it work?
A small, medium and large thumbnail is generated for every attachment of a Media message of type video or image. For eg, if a Media message of type video is sent with 2 attachments, the links to these thumbnails are then provided in the metadata of the message as shown below:The
You can iterate over
url_small
, url_medium
& url_large
keys to the outside of attachments
are the thumbnail URLs for the first attachment from the attachments
array. These have been retained for backward compatibility only.You can iterate over
attachments
array for better implementation.Implementation
You can make use of thegetMetadata()
method to extract the thumbnail details for a message.
The url
field is the link to the actual image or video.
You can make use of url_small
, url_medium
& url_large
keys for showing thumbnails based on the device of your end users.
Unlike image thumbnails, which are normally generated in milliseconds, video thumbnails may take a little longer. Before viewing the preview, we recommend verifying to see if the file exists. If the difference between message sentAt and the current time is less than 5 seconds, you can set a simple timer to monitor every second.