Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Create video message from local file

Create a video message from local video and thumbnail image filesystem paths.

Copy

Creates a video message object using local filesystem paths for both the video file and cover thumbnail image.

Code example

import sdk, { CreateVideoMessageReq, CreateVideoMessageResp } from '@openimsdk/imsdk';

const request: CreateVideoMessageReq = {
  videoSourcePath: videoPath,
  videoType: 'video/mp4',
  duration: 18,
  snapshotSourcePath: coverPath,
};
const response: CreateVideoMessageResp = await sdk.createVideoMessage(request);
const message = response.message;

Parameters

ParameterTypeRequiredDescription
videoSourcePathstringYesLocal filesystem path to the video file readable by the native SDK.
videoTypestringYesVideo MIME type (such as video/mp4).
durationnumberYesVideo playback duration in seconds.
snapshotSourcePathstringYesLocal filesystem path to the cover thumbnail image.

Return value

Returns a Promise resolving to CreateVideoMessageResp:

PropertyTypeDescription
messageIMMessageLocally instantiated video message object.

State changes after the call

Both video and cover snapshot paths must be readable by the native SDK. duration is in seconds, and videoType represents the true MIME type. Promise resolution creates the message object locally; calling Send message subsequently uploads both files through the SDK and transmits the message.