SDKsuni-app / uni-app x
Create an audio message from a URL
Construct a pending audio message from an already-uploaded audio URL and metadata.
Invoke createSoundMessageByURL() when an audio file has already been uploaded to your application server or storage provider and has a publicly accessible remote URL.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
uuid | string | No | Unique audio identifier returned by the upload service. |
soundPath | string | No | Original local file path; pass an empty string "" when only remote URLs exist. |
sourceUrl | string | Recommended | Publicly accessible remote URL for audio playback. |
dataSize | number | Recommended | File size in bytes. |
duration | number | Recommended | Audio playback duration in seconds. |
Code example
import { createSoundMessageByURL } from '@/uni_modules/unix-openim-sdk'
const message = await createSoundMessageByURL({
uuid: uploaded.uuid,
soundPath: '',
sourceUrl: uploaded.url,
dataSize: uploaded.size,
duration: 12,
})
if (message == null) returnWhile individual fields are typed as optional, creating a functional audio message requires a valid sourceUrl alongside the actual file size and playback duration. Avoid using transient URLs that expire quickly.
Return value
The Promise resolves with an OpenIMMessageItem | null object.
State changes after the call
Pass the constructed message item to Send a non-OSS message to transmit the audio message without repeating the upload process. Track message lifecycle using clientMsgID.
Was this page helpful?