Daniel Givoni
Daniel Givoni

Reputation: 743

IllegalStateException thrown when recording with vorbis AudioEncoder

i'm trying to record audio capture useing ogg vorbis format, but i get an IllegalStateException when calling start() when useing mp3 format all is fine my MediaRecorder code snnipet:

if there is an option to use MediaRecorder with Opus encoder thats fine, i would like an example. i'm looking for a free record format so i cannot use mp3.

 private void startRecording() {
    if (IsRecording()) {
        stopRecording();
    }
    mRecorder = new MediaRecorder();
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
   // mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.WEBM);
    mRecorder.setOutputFile(mFileName);
    //mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.VORBIS);
    StartRecording = false;
    try {
        mRecorder.prepare();
    } catch (IOException e) {
        Log.e(LOG_TAG, "prepare() failed");
    }

    mRecorder.start();
    StartRecording = true;

}

my log :

    FATAL EXCEPTION: main
 java.lang.IllegalStateException
     at android.media.MediaRecorder.native_start(Native Method)
     at android.media.MediaRecorder.start(MediaRecorder.java:784)
     at com.sparkup.device.AudioCapture.startRecording(AudioCapture.java:92)
     at com.sparkup.device.AudioCapture.onRecord(AudioCapture.java:43)
     at com.sparkup.device.SparkupActivity$10.run(SparkupActivity.java:803)
     at android.os.Handler.handleCallback(Handler.java:739)
     at android.os.Handler.dispatchMessage(Handler.java:95)
     at android.os.Looper.loop(Looper.java:135)
     at android.app.ActivityThread.main(ActivityThread.java:5349)
     at java.lang.reflect.Method.invoke(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:372)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)

Upvotes: 0

Views: 492

Answers (0)

Related Questions