跳到主要内容

createSoundMessageByFile

功能介绍

说明

根据文件对象创建音频消息。

注意

仅 web 端支持

函数原型

IMSDK.createSoundMessageByFile({
uuid: string;
soundPath: string;
sourceUrl: string;
dataSize: number;
duration: number;
soundType: string;
file: File;
}, operationID?: string): Promise<WsResponse<MessageItem>>

输入参数

参数名称参数类型是否必填描述
soundPathstring文件绝对路径,如果没有传空字符即可
durationnumber录音时长
uuidstring文件唯一 ID
sourceUrlstring录音下载地址,自行上文件并通过sendMessageNotOss 发送时,需要传入远程 url,否则为空字符串
dataSizestring文件大小
soundTypestring文件类型,一般为后缀名
fileFile文件对象

返回结果

参数名称参数类型描述
Promise.then()Promise<WsResponse<MessageItem>>调用成功回调
Promise.catch()Promise<WsResponse>调用失败回调

代码示例

import { getSDK } from 'open-im-sdk-wasm';
const IMSDK = getSDK();

// use in electron with ffi
// import { getWithRenderProcess } from '@openim/electron-client-sdk/lib/render';
// const { instance: IMSDK } = getWithRenderProcess();

// use in mini program
// import { OpenIMSDK } from 'open-im-sdk';
// const IMSDK = new OpenIMSDK();

IMSDK.createSoundMessageByFile({
soundPath: soundFile.path,
duration: 6,
uuid: 'uuid',
sourceUrl: '',
dataSize: soundFile.size,
soundType: soundFile.type,
file: soundFile,
})
.then(({ data }) => {
// 调用成功
})
.catch(({ errCode, errMsg }) => {
// 调用失败
});