Browse SDKs · uni-app / uni-app x
Platform
SDKsuni-app / uni-app x

Create a video message from a local file

Create a pending video message from accessible local video and cover thumbnail file paths.

Copy

Invoke createVideoMessageFromFullPath() to construct a pending video message using local file paths for both the video and its cover thumbnail snapshot.

Parameters

ParameterTypeRequiredDescription
videoPathstringYesLocal video file path accessible to the native runtime.
videoTypestringYesVideo MIME type (for example, 'video/mp4').
durationnumberYesVideo duration in seconds.
snapshotPathstringYesLocal thumbnail cover image path accessible to the native runtime.

Code example

import {
  createVideoMessageFromFullPath,
} from '@/uni_modules/unix-openim-sdk'

const message = await createVideoMessageFromFullPath({
  videoPath: `${uni.env.USER_DATA_PATH}/demo.mp4`,
  videoType: 'video/mp4',
  duration: 18,
  snapshotPath: `${uni.env.USER_DATA_PATH}/demo-cover.jpg`,
})
if (message == null) return

Both paths should be POSIX absolute paths or unifile:// URIs. When handling files generated by video recorders or camera pickers, persist them in uni.env.USER_DATA_PATH if they will not be transmitted immediately. Specify duration in seconds and ensure the cover image accurately reflects the video content.

Return value

The Promise resolves with an OpenIMMessageItem | null object.

State changes after the call

Pass the constructed message item to Send a message. The SDK automatically uploads the video and thumbnail before delivering the message payload. Monitor upload progress with onSendMessageProgress and index updates by clientMsgID.