createSoundMessageByURL
Feature Introduction
When you need to store resources yourself, create a voice message to send to the other party after uploading the voice through the API and obtaining the download address.
Messages created by this API must be sent via sendMessageNotOss.
- iOS
- Android
- Flutter
- uni-app
- Browser/Electron/MiniProgram
- React-Native
- Unity
Function Prototype
Future<Message> createSoundMessageByURL({
required SoundElem soundElem,
String? operationID,
})
Input Parameters
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
soundElem | SoundElem | Yes |
Return Value
Name | Type | Description |
---|---|---|
~ | Message | Successful Return |
Code Sample
Message msg = await OpenIM.iMManager.messageManager.createSoundMessageByURL(soundElem: soundElem);
//todo
Function Prototype
+ (OIMMessageInfo *)createSoundMessageByURL:(NSString *)fileURL
duration:(NSInteger)duration
size:(NSInteger)size;
Input Parameters
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
fileURL | NSString | Yes | Audio URL |
duration | NSInteger | Yes | Duration |
size | NSInteger | Yes | File Size |
Return Value
Name | Type | Description |
---|---|---|
message | OIMMessageInfo | Successful Return |
Code Sample
OIMMessageInfo *message = [OIMMessageInfo createSoundMessageByURL:@"" duration:1 size:1024];
Function Prototype
public Message createSoundMessageByURL(SoundElem soundElem)
Input Parameters
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
soundElem | SoundElem | Yes |
Return Value
Name | Type | Description |
---|---|---|
~ | Message | Successful Return |
Code Sample
Message Message= OpenIMClient.getInstance().messageManager.createSoundMessageByURL( soundElem)
Function Prototype
IMSDK.createSoundMessage({
uuid: string;
soundPath: string;
sourceUrl: string;
dataSize: number;
duration: number;
soundType?: string;
}, operationID?: string): Promise<WsResponse<MessageItem>>
Input Parameters
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
soundPath | string | Yes | File path, just pass an empty string |
duration | number | Yes | Recording Duration |
uuid | string | Yes | Unique File ID |
sourceUrl | string | Yes | Recording download address. When you upload the file yourself and send it via sendMessageNotOss, you need to enter the remote URL, otherwise, it's an empty string |
dataSize | string | Yes | File Size |
soundType | string | Yes | File Type, usually the extension name |
Return Value
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<WsResponse<MessageItem>> | Successful Callback |
Promise.catch() | Promise<WsResponse> | Failed Callback |
Code Sample
import { getSDK } from '@openim/wasm-client-sdk';
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 { getSDK } from '@openim/client-sdk';
// const IMSDK = getSDK();
IMSDK.createSoundMessage({
soundPath: '',
duration: 6,
uuid: 'uuid',
sourceUrl: '',
dataSize: 1024,
soundType: 'mp3',
})
.then(({ data }) => {
// Successful call
})
.catch(({ errCode, errMsg }) => {
// Failed call
});
Function Prototype
IMSDK.asyncApi('createSoundMessageByURL', operationID: string, {
uuid: string;
soundPath: string;
sourceUrl: string;
dataSize: number;
duration: number;
soundType: string;
}): Promise<MessageItem>
Input Parameters
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
operationID | string | Yes | Operation ID, used for problem location, should remain unique. It's recommended to use the current time and a random number |
soundPath | string | Yes | File path, just pass an empty string |
duration | number | Yes | Recording Duration |
uuid | string | Yes | Unique File ID |
sourceUrl | string | Yes | Picture download address. When you upload the file yourself and send it via sendMessageNotOss, you need to enter the remote URL, otherwise, it's an empty string |
dataSize | string | Yes | File Size |
soundType | string | Yes | File Type, usually the extension name |
Return Value
The function is made Promise-based through the
openim-uniapp-polyfill
package. When calling, usethen
andcatch
to determine and handle successful and failed callbacks.
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<MessageItem> | Successful Callback |
Promise.catch() | Promise<CatchResponse> | Failed Callback |
Code Example
import IMSDK from 'openim-uniapp-polyfill';
IMSDK.asyncApi('createSoundMessageByURL', IMSDK.uuid(), {
soundPath: '',
duration: 6,
uuid: 'uuid',
sourceUrl: '',
dataSize: 1024,
soundType: 'mp3',
})
.then((data) => {
// Call succeeded
})
.catch(({ errCode, errMsg }) => {
// Call failed
});
Function Prototype
OpenIMSDKRN.createSoundMessageByURL({
uuid: string,
soundPath: string,
sourceUrl: string,
dataSize: number,
duration: number,
soundType: string,
}, operationID: string): Promise<MessageItem>
Input Parameters
| Parameter Name | Parameter Type | Mandatory | Description | | ----------- | -------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------- | | | soundPath | string | Yes | File path, just pass an empty string | | duration | number | Yes | Recording Duration | | uuid | string | Yes | File unique ID | | sourceUrl | string | Yes | Picture download address. When you upload the file yourself and send it via sendMessageNotOss, you need to enter the remote URL, otherwise, it's an empty string | | dataSize | string | Yes | File size | | soundType | string | Yes | File type, usually the extension | | operationID | string | Yes | Operation ID, used for problem location, keep unique, suggest using current time and random number
Return Result
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<MessageItem> | Callback on successful call |
Promise.catch() | Promise<CatchResponse> | Callback on failed call |
Code Example
import OpenIMSDKRN from "open-im-sdk-rn";
OpenIMSDKRN.createSoundMessageByURL({
soundPath: '',
duration: 6,
uuid: 'uuid',
sourceUrl: '',
dataSize: 1024,
soundType: 'mp3',
}, 'operationID')
.then((data) => {
// Call succeeded
})
.catch(({ errCode, errMsg }) => {
// Call failed
});
Function Prototype
public static Message CreateSoundMessageByURL(SoundBaseInfo soundBaseInfo);
Input Parameter
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
soundBaseInfo | SoundBaseInfo | Yes | Audio Setting |
Return Result
Parameter Name | Type | Description |
---|---|---|
message | Message | Message Struct |
Code Example
var msg = IMSDK.CreateSoundMessageByURL(new SoundBaseInfo(){
});