// Path: chat-message-adapter/src/main/java/com/quickblox/ui/kit/chatmessage/adapter/media/recorder/exceptions/MediaRecorderException.java
// public class MediaRecorderException extends Exception {
// 
//     public MediaRecorderException(String s) {
//         super(s);
//     }
// }
// 
// Path: chat-message-adapter/src/main/java/com/quickblox/ui/kit/chatmessage/adapter/media/recorder/listeners/QBMediaRecordListener.java
// public interface QBMediaRecordListener {
// 
//     void onMediaRecorded(File file);
// 
//     void onMediaRecordError(MediaRecorderException e);
// 
//     void onMediaRecordClosed();
// }
// 
// Path: chat-message-adapter/src/main/java/com/quickblox/ui/kit/chatmessage/adapter/media/recorder/model/QBMediaRecorder.java
// public abstract class QBMediaRecorder<T> {
// 
//     public abstract void startRecord();
// 
//     public abstract void stopRecord();
// 
//     public abstract void cancelRecord();
// }


import android.content.Context;
import android.media.MediaRecorder;
import android.util.Log;
import com.quickblox.ui.kit.chatmessage.adapter.media.recorder.exceptions.MediaRecorderException;
import com.quickblox.ui.kit.chatmessage.adapter.media.recorder.listeners.QBMediaRecordListener;
import com.quickblox.ui.kit.chatmessage.adapter.media.recorder.model.QBMediaRecorder;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
        if (recordListener != null) {
            recordListener.onMediaRecordClosed();
        }
    }

    @Override
    public void stopRecord() {
        stopAndReleaseMediaRecorder();
        sendResult();
    }

    private void initMediaRecorder() {
        recorder = new MediaRecorder();
        recorder.setAudioSource(configurationBuilder.audioSource);
        recorder.setOutputFormat(configurationBuilder.outputFormat);
        recorder.setOutputFile(configurationBuilder.filePath);
        recorder.setAudioChannels(configurationBuilder.channels);
        recorder.setAudioEncoder(configurationBuilder.audioEncoder);
        recorder.setAudioEncodingBitRate(configurationBuilder.bitRate);
        recorder.setAudioSamplingRate(configurationBuilder.samplingRate);
        recorder.setMaxDuration(configurationBuilder.duration);
        recorder.setOnInfoListener(new OnInfoListenerImpl());
        recorder.setOnErrorListener(new OnErrorListenerImpl());
    }

    private void prepareStartMediaRecorder() {
        try {
            recorder.prepare();
            recorder.start();
        } catch (IOException e) {
// Path: chat-message-adapter/src/main/java/com/quickblox/ui/kit/chatmessage/adapter/media/recorder/exceptions/MediaRecorderException.java
// public class MediaRecorderException extends Exception {
// 
//     public MediaRecorderException(String s) {
//         super(s);
//     }
// }
// 
// Path: chat-message-adapter/src/main/java/com/quickblox/ui/kit/chatmessage/adapter/media/recorder/listeners/QBMediaRecordListener.java
// public interface QBMediaRecordListener {
// 
//     void onMediaRecorded(File file);
// 
//     void onMediaRecordError(MediaRecorderException e);
// 
//     void onMediaRecordClosed();
// }
// 
// Path: chat-message-adapter/src/main/java/com/quickblox/ui/kit/chatmessage/adapter/media/recorder/model/QBMediaRecorder.java
// public abstract class QBMediaRecorder<T> {
// 
//     public abstract void startRecord();
// 
//     public abstract void stopRecord();
// 
//     public abstract void cancelRecord();
// }


// Path: chat-message-adapter/src/main/java/com/quickblox/ui/kit/chatmessage/adapter/media/recorder/AudioRecorder.java
import android.content.Context;
import android.media.MediaRecorder;
import android.util.Log;
import com.quickblox.ui.kit.chatmessage.adapter.media.recorder.exceptions.MediaRecorderException;
import com.quickblox.ui.kit.chatmessage.adapter.media.recorder.listeners.QBMediaRecordListener;
import com.quickblox.ui.kit.chatmessage.adapter.media.recorder.model.QBMediaRecorder;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

        if (recordListener != null) {
            recordListener.onMediaRecordClosed();
        }
    }

    @Override
    public void stopRecord() {
        stopAndReleaseMediaRecorder();
        sendResult();
    }

    private void initMediaRecorder() {
        recorder = new MediaRecorder();
        recorder.setAudioSource(configurationBuilder.audioSource);
        recorder.setOutputFormat(configurationBuilder.outputFormat);
        recorder.setOutputFile(configurationBuilder.filePath);
        recorder.setAudioChannels(configurationBuilder.channels);
        recorder.setAudioEncoder(configurationBuilder.audioEncoder);
        recorder.setAudioEncodingBitRate(configurationBuilder.bitRate);
        recorder.setAudioSamplingRate(configurationBuilder.samplingRate);
        recorder.setMaxDuration(configurationBuilder.duration);
        recorder.setOnInfoListener(new OnInfoListenerImpl());
        recorder.setOnErrorListener(new OnErrorListenerImpl());
    }

    private void prepareStartMediaRecorder() {
        try {
            recorder.prepare();
            recorder.start();
        } catch (IOException e) {
            notifyListenerError(new MediaRecorderException(e.getMessage()));