createSoundMessage
Introduction
Create a sound or audio message.
To create an audio message, you need to get the local audio file path and audio duration first, the latter of which can be used for display on the receiver UI.
During message sending, the audio is uploaded to the server, and the upload progress is called back. The message is sent after the audio is uploaded successfully.
For details, you can referring to this document.
Parameter details
Parameter name | Parameter type | Required | Description |
---|---|---|---|
soundPath | string | yes | Absolute path of the local audio file. |
duration | number | yes | The duration of the audio. |
Returned template
V2TimValueCallback<V2TimMsgCreateInfoResult>
{
code: number,
desc: string,
data: {
id: string,
messageInfo: V2TimMessage,
}
}
Return value details
name | type | description |
---|---|---|
code | number | Request result: Error codes. 0 means success. |
desc | string | The description of the error. It will be empty if success. |
data | V2TimMsgCreateInfoResult | The sound message created. |
Code example
import { TencentImSDKPlugin } from 'react-native-tim-js';
const createSoundMessageRes = await TencentImSDKPlugin.v2TIMManager
.getMessageManager()
.createSoundMessage(
'本地录音文件绝对路径',
10
);
if (createSoundMessageRes.code === 0) {
const id = createSoundMessageRes.data?.id;
const sendMessageRes = await TencentImSDKPlugin.v2TIMManager
.getMessageManager()
.sendMessage({ id: id!, receiver: 'userID', groupID: 'groupID' });
if (sendMessageRes.code === 0) {
}
}