SDKsWASM
使用文件创建视频消息
使用 WASM SDK 从浏览器视频和封面图文件创建视频消息。
createVideoMessageByFile() 使用浏览器中的视频文件、视频封面图及其元数据创建消息。SDK 字段名仍使用 snapshot,正文统一称为“视频封面图”。
参数说明
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
videoFile | File | 是 | 浏览器中的原始视频文件。 |
snapshotFile | File | 是 | 浏览器中的视频封面图文件。 |
videoPath | string | 是 | 视频文件的本地名称或业务路径。 |
duration | number | 是 | 视频时长,单位为秒。 |
videoType | string | 是 | 视频 MIME 类型。 |
videoUUID | string | 是 | 视频资源的唯一标识。 |
videoUrl | string | 是 | 视频地址;由文件创建时传空字符串。 |
videoSize | number | 是 | 视频大小,单位为字节。 |
snapshotPath | string | 是 | 封面图文件的本地名称或业务路径。 |
snapshotUUID | string | 是 | 封面图资源的唯一标识。 |
snapshotSize | number | 是 | 封面图大小,单位为字节。 |
snapshotUrl | string | 是 | 封面图地址;由文件创建时传空字符串。 |
snapshotWidth | number | 是 | 封面图宽度,单位为像素。 |
snapshotHeight | number | 是 | 封面图高度,单位为像素。 |
snapShotType | string | 否 | 封面图 MIME 类型。 |
const { data: message } = await openimsdk.createVideoMessageByFile({
videoFile,
snapshotFile,
videoPath: videoFile.name,
duration,
videoType: videoFile.type,
videoUUID: crypto.randomUUID(),
videoUrl: '',
videoSize: videoFile.size,
snapshotPath: snapshotFile.name,
snapshotUUID: crypto.randomUUID(),
snapshotSize: snapshotFile.size,
snapshotUrl: '',
snapshotWidth,
snapshotHeight,
snapShotType: snapshotFile.type,
});视频时长使用秒;浏览器得到毫秒时长时,先换算为秒再传入。Promise 成功只创建待发送对象;后续使用 sendMessage() 上传并发送。
这个页面有帮助吗?