16

i searched to check if this question is no dup , i see some has no answer and others did not help.

this is my code :

private void startRecording()
{
            mRecorder = new MediaRecorder();
            mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
            mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

            mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
              mFileName += "/recordedHeckPost_.3gp";

            mRecorder.setOutputFile(mFileName);                  

                try {
                    mRecorder.prepare();
                    //Thread.sleep(2000);
                    mRecorder.start();                  
        }
                catch (InterruptedException e) 
                {   // TODO Auto-generated catch block
            e.printStackTrace();
        }     
            catch(IllegalStateException e)
            {
                e.printStackTrace();
            } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
}

private void stopRecording()
{
        mRecorder.stop();
        mRecorder.release();
        mRecorder = null;
}

After running this code (On Nexus 5) i get the below start failed -38 exception:

05-31 18:17:39.404: E/MediaRecorder(2464): start failed: -38
05-31 18:17:39.404: W/System.err(2464): java.lang.IllegalStateException
05-31 18:17:39.404: W/System.err(2464):     at android.media.MediaRecorder.start(Native Method)

Thanks.

Robocide
  • 6,353
  • 4
  • 37
  • 41

2 Answers2

25

Found the solution , it appears i had some other service in the background which is using AudioRecord and uses the mic as well.... so thats the -38 :)

Robocide
  • 6,353
  • 4
  • 37
  • 41
  • Which background service was this in particular? – Vinay Gaba Nov 04 '14 at 19:43
  • 2
    It was one of my my app services not OS – Robocide Nov 04 '14 at 20:09
  • 1
    Found it! From another app I tested whose icon I had hidden!Damn I would never never realized it without the answer about other service in background.Thanks! – Vinay Gaba Nov 04 '14 at 20:51
  • how can i find that other service running in background for recording or using mic? – SRam Jan 12 '17 at 07:02
  • just check in your source code of your application for the strings "AudioRecord" or "MediaRecorder" .... or some other way to find if you have code that uses the mic.... – Robocide May 31 '17 at 09:27
  • Did you find any solution to fix this without removing the background services?. I am using https://github.com/JorenSix/TarsosDSP to detect the pitch from the microphone when recording the video. So can you please help me out to fix this issue. – hasan_shaikh Apr 05 '18 at 12:09
0

In my case that error (MediaRecorder: start failed: -38) was appearing after switching to second camera when I forgot to release MediaRecorder during closing (first) camera:

mediaRecorder?.release()
mediaRecorder = null
Francis
  • 6,788
  • 5
  • 47
  • 64