createSoundMessageByURL
Description
info
When you need to store resources yourself, upload the audio via API and obtain the download URL, then create an audio message.
Note
Messages created through 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 | Required | Description |
|---|---|---|---|
| soundElem | SoundElem | Yes |
Return Result
| Name | Type | Description |
|---|---|---|
| ~ | Message | Success return |
Code Example
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 | Required | Description |
|---|---|---|---|
| fileURL | NSString | Yes | Audio URL |
| duration | NSInteger | Yes | Duration |
| size | NSInteger | Yes | File size |
Return Result
| Name | Type | Description |
|---|---|---|
| message | OIMMessageInfo | Success return |
Code Example
OIMMessageInfo *message = [OIMMessageInfo createSoundMessageByURL:@"" duration:1 size:1024];
Function Prototype
public Message createSoundMessageByURL(SoundElem soundElem)
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| soundElem | SoundElem | Yes |
Return Result
| Name | Type | Description |
|---|---|---|
| ~ | Message | Success return |
Code Example
Message Message= OpenIMClient.getInstance().messageManager.createSoundMessageByURL( soundElem)
Function Prototype
IMSDK.createFileMessageByURL({
uuid: string;
soundPath: string;
sourceUrl: string;
dataSize: number;
duration: number;
soundType?: string;
}, operationID?: string): Promise<WsResponse<MessageItem>>
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| soundPath | string | Yes | File path, empty string is fine |
| duration | number | Yes | Recording duration |
| uuid | string | Yes | Unique file ID |
| sourceUrl | string | Yes | Recording download address. When uploading the file yourself and sending via sendMessageNotOss, this needs to be the remote URL; otherwise, it should be an empty string |
| dataSize | string | Yes | File size |
| soundType | string | Yes | File type, usually the extension |
Return Result
| Parameter Name | Parameter Type | Description |
|---|---|---|
| Promise.then() | Promise<WsResponse<MessageItem>> | Success callback |
| Promise.catch() | Promise<WsResponse> | Failure callback |
Code Example
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.createFileMessageByURL({
soundPath: '',
duration: 6,
uuid: 'uuid',
sourceUrl: '',
dataSize: 1024,
soundType: 'mp3',
})
.then(({ data }) => {
// Call successful
})
.catch(({ errCode, errMsg }) => {
// Call failed
});
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 | Required | Description |
|---|---|---|---|
| operationID | string | Yes | Operation ID, used to pinpoint issues, keep unique, prefer time+random |
| soundPath | string | Yes | File path, empty string is fine |
| duration | number | Yes | Recording duration |
| uuid | string | Yes | Unique file ID |
| sourceUrl | string | Yes | Audio download address. When uploading the file yourself and sending via sendMessageNotOss, this needs to be the remote URL; otherwise, it should be an empty string |
| dataSize | string | Yes | File size |
| soundType | string | Yes | File type, usually the extension |
Return Result
Use the
openim-uniapp-polyfillpackage to make the function Promise. When calling, you need to usethenandcatchto determine and handle success and failure callbacks.
| Parameter Name | Parameter Type | Description |
|---|---|---|
| Promise.then() | Promise<MessageItem> | Success callback |
| Promise.catch() | Promise<CatchResponse> | Failure 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 successful
})
.catch(({ errCode, errMsg }) => {
// Call failed
});
Function Prototype
OpenIMSDK.createSoundMessageByURL({
uuid: string,
soundPath: string,
sourceUrl: string,
dataSize: number,
duration: number,
soundType: string,
}, operationID?: string): Promise<MessageItem>
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| soundPath | string | Yes | File path, empty string is fine |
| duration | number | Yes | Recording duration |
| uuid | string | Yes | Unique file ID |
| sourceUrl | string | Yes | Audio download address. When uploading the file yourself and sending via sendMessageNotOss, this needs to be the remote URL; otherwise, it should be an empty string |
| dataSize | string | Yes | File size |
| soundType | string | Yes | File type, usually the extension |
| operationID | string | No | Operation ID, used to pinpoint issues, keep unique, prefer time+random |
Return Result
| Parameter Name | Parameter Type | Description |
|---|---|---|
| Promise.then() | Promise<MessageItem> | Success callback |
| Promise.catch() | Promise<OpenIMApiError> | Failure callback |
Code Example
import OpenIMSDK from "@openim/rn-client-sdk";
OpenIMSDK.createSoundMessageByURL({
soundPath: '',
duration: 6,
uuid: 'uuid',
sourceUrl: '',
dataSize: 1024,
soundType: 'mp3',
})
.then((data) => {
// Call successful
})
.catch((error) => {
// Call failed
});
Function Prototype
public static Message CreateSoundMessageByURL(SoundElem soundBaseInfo);
Input Parameters
| Parameter Name | Parameter Type | Required | Description |
|---|---|---|---|
| soundBaseInfo | SoundElem | Yes | Audio configuration |
Return Result
| Name | Type | Description |
|---|---|---|
| message | Message | Success return |
Code Example
var msg = IMSDK.CreateSoundMessageByURL(new SoundElem(){
});