Browse SDKs · Android
Platform
SDKsAndroid

Create an audio message from a URL

Use SoundElem to create an audio message for an uploaded resource.

Copy

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

ParameterTypeRequiredDescription
soundElemSoundElemYesAudio 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

  1. Local initialization: Initializes the local Message structure without initiating network uploads.
  2. Transmission: Because the media asset is pre-hosted, call Send a message without OSS upload to deliver the message without redundant uploads.