Browse SDKs · uni-app / uni-app x
Platform
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.

Copy

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

ParameterTypeRequiredDescription
uuidstringNoUnique audio identifier returned by the upload service.
soundPathstringNoOriginal local file path; pass an empty string "" when only remote URLs exist.
sourceUrlstringRecommendedPublicly accessible remote URL for audio playback.
dataSizenumberRecommendedFile size in bytes.
durationnumberRecommendedAudio 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) return

While 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.