kailash09dabhi / OmRecorder

A Simple Pcm / Wav audio recorder with nice api. https://play.google.com/store/apps/details?id=com.kingbull.omrecorder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

stop() called on an uninitialized AudioRecord.

ashishkumart opened this issue · comments

Hi,
I am using this library and when I am recording second time and stopping, I am getting below error. Please suggest.
Thank You.

Error is

java.lang.IllegalStateException: stop() called on an uninitialized AudioRecord.

**Code to start and stop **

`View.OnTouchListener touchListener = new View.OnTouchListener() {
@OverRide
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (permissionToRecordAccepted && permissionToReadExternalStorage && permissionToWriteExternalStorage) {

                //startPulseAnimation();
                timerTextView.setVisibility(View.VISIBLE);
                countDownTimer.start();
                recorder.startRecording();
            }


        } else if (event.getAction() == MotionEvent.ACTION_UP) {

            timerTextView.setVisibility(View.INVISIBLE);
            countDownTimer.cancel();
            try {
                recorder.stopRecording(); // Here I am getting error.
                if (!TextUtils.isEmpty(mVerificationId)) {
                    mPresenter.configureVoice(mVerificationId, Utility.getDeviceId(), file().getPath(), audioBytes);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return true;
    }
}`

This recorder.stopRecording(); runs before the recorder is actually initialized. Put these try and catch blocks into an if statement that checks if the recorder is not null first. Or simply create a flag isRecording that changes when you start and stop recording

I've got the same issue, i tried with if statement but that don't work, maybe I don't do it correctly. And I don't understand flag ?

I use isRecording but I got the same problem.

I think this problem comes if your device don't support the sample rate you define like 44100 Hz, some devices supports and some not.

For reference :-

https://stackoverflow.com/questions/4843739/audiorecord-object-not-initializing
https://stackoverflow.com/questions/28539717/android-startrecording-called-on-an-uninitialized-audiorecord-when-samplerate/28539778

java.lang.IllegalStateException: stop() called on an uninitialized AudioRecord.
You will get this error only when the AudioRecord object is not properly intialized. It may happen if you use stopRecording() before calling startRecording().

from AOSP,

after stop is called, mState = STATE_UNINITIALIZED;
from startRecording ,

if (mState != STATE_INITIALIZED) {
           throw new IllegalStateException("startRecording() called on an "
                   + "uninitialized AudioRecord.");
       }

mState only resets from the constructor
=> construct new object for second record