Creating

Post a Text Message to a Channel

To post a text message to a channel:

VoiceLayerMaessage message = channel.postMessage(text);

or

channel.postMessage(text, new VoiceLayerCreateCallback<VoiceLayerMessage>() {
    @Override
    public void onCreateComplete(VoiceLayerMessage message, VoiceLayerException exception) {

    }
});

Post a Text Message to a Channel with Meta Data

First prepare the meta data:

Map<String, Object> data = new HashMap<String, Object>();
data.put(metaKey, metaValue);
data.put(metaKey2, metaValue2);

then:

VoiceLayerMaessage message = channel.postMessage(text, data);

or

channel.postMessage(text, data, new VoiceLayerCreateCallback<VoiceLayerMessage>() {
    @Override
    public void onCreateComplete(VoiceLayerMessage message, VoiceLayerException exception) {

    }
});

Record a Voice Message to a Channel

First get a reference to the VoiceLayerMessageRecorder:

VoiceLayerMessageRecorder recorder = client.getMessageRecorder();

optionally you can set a listener for recorder events:

recorder.setRecorderEventListener(new VoiceLayerRecorderEventListener() {

    @Override
    public void onRecorderEvent(VoiceLayerRecorderEvent event, VoiceLayerMessage message) {
        // Called when recording starts and finishes.
    }

    @Override
    public void onRecordingFailed(VoiceLayerRecorderException exception) {
        // Called if recording fails.
    }

});

then start recording without meta data:

VoiceLayerMessage message = recorder.startRecording(channel);

or with meta data:

Map<String, Object> data = new HashMap<String, Object>();
data.put(metaKey, metaValue);
data.put(metaKey2, metaValue2);

VoiceLayerMessage message = recorder.startRecording(channel, data);

when you are finished recording:

float messageDuration = recorder.stopRecording();

when finished with the recorder don't forget to clear the listener to avoid potential memory leaks:

recorder.setRecorderEventListener(null);

Avoiding Recorder Errors

It is recommended that you subscribe to recorder events and wait for a VoiceLayerRecorderEvent.FINISH before attempting to record your next voice message. The recorder will not be immediately ready after you call recorder.stopRecording as it has to finish processing the recorded message. Once the VoiceLayerRecorderEvent.FINISH has been delivered, however, the recorder will be ready to record again.