SDKsAndroid
Create an audio message from a URL
Use SoundElem to create an audio message for an uploaded resource.
Construct a voice or audio message object using a pre-uploaded remote audio URL hosted on your cloud storage or CDN. The SDK does not re-upload the file, making this suitable for applications managing their own file storage pipelines.
Code example
SoundElem soundElem = new SoundElem();
soundElem.setSourceUrl("https://example.com/audio/voice_sample.m4a");
soundElem.setDataSize(128000L);
soundElem.setDuration(15L);
Message message = OpenIMClient.getInstance().messageManager.createSoundMessageByURL(soundElem);Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
soundElem | SoundElem | Yes | Audio model object. Must specify the remote download URL sourceUrl, audio duration duration, and file size dataSize. |
Return value
Returns the created Message object with contentType set to MessageType.VOICE.
State changes after the call
- Local initialization: Initializes the local
Messagestructure without initiating network uploads. - Transmission: Because the media asset is pre-hosted, call Send a message without OSS upload to deliver the message without redundant uploads.
Was this page helpful?