1

the part of the code that throws exception:

        recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);

        recorder.setOutputFile("test.3gp");
        recorder.prepare();
        recorder.start();

and i'm getting this exception:

E/MediaRecorder: start failed: -38
W/System.err: java.lang.IllegalStateException
W/System.err:     at android.media.MediaRecorder.start(Native Method)
W/System.err:     at com.example.amit.recording.RecordService.startRecording(RecordService.java:280)
W/System.err:     at com.example.amit.recording.RecordService.onStartCommand(RecordService.java:141)
W/System.err:     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3422)
W/System.err:     at android.app.ActivityThread.access$2200(ActivityThread.java:181)
W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1572)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err:     at android.os.Looper.loop(Looper.java:145)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6117)
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at java.lang.reflect.Method.invoke(Method.java:372)
W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

the "recorder.start()" is causing this. also when i'm stopping the record, getting this: "stop called in an invalid state: 0" btw - got all the permissions i need in the manifest. thanks!!

EDIT

i added "Thread.sleep(2000);" before "prepare()" & "start()", and now it saved a 3gp file in the correct path, but the exceptions are still there - on start() & on stop(). why is it happening?!

Jahrk
  • 11
  • 6

1 Answers1

0

If you targeting greater then 22 then you must have to implement runtime permissions. See here for how to implement runtime permission in android.

Najeeb Idrees
  • 453
  • 6
  • 15
  • It doesn't seem like this is the problem – Jahrk Feb 15 '17 at 15:16
  • Please check path of file and also replace default output line. `mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);` – Najeeb Idrees Feb 15 '17 at 15:22
  • not working, thanks for trying. i edited the question, please read it – Jahrk Feb 15 '17 at 15:27
  • this problem causing by this Audio source `recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);` not working on your device and android! change that to `recorder.setAudioSource(MediaRecorder.AudioSource.MIC);` – Najeeb Idrees Feb 15 '17 at 15:31
  • MIC throws the same exception. Also maybe i should added, the error i get when i stop the record: "stop called in an invalid state: 0" – Jahrk Feb 15 '17 at 15:33