Question

I have googled about it but didn't find any solution

I am recording incoming and outgoing calls

code works fine with outgoing call but gives exception on incoming call

    recorder = new MediaRecorder();

    File sdCard = Environment.getExternalStorageDirectory();
    File dir = new File(sdCard.getAbsolutePath() + "/OK");
    dir.mkdirs();

    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
 recorder.setOutputFile(Environment.getExternalStorageDirectory().getAbsolutePath()+"/OK/"+"yes"+".3gpp");
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

    try {
       recorder.prepare();
       recorder.start();
    } catch (IllegalStateException e) {
         Log.d("illegal",e.toString());
    } catch (IOException e) {
         Log.d("io",e.toString());
   }

Logcat

02-23 01:43:08.346  11231-11231/com.example.myapps.acr **I/record﹕ start**
02-23 01:43:08.426  11231-11231/com.example.myapps.acr **E/MediaRecorder﹕ start failed: -38**
02-23 01:43:08.426  11231-11231/com.example.myapps.acr **D/illegal﹕ java.lang.IllegalStateException**

Please help why its not working on incoming calls..

Was it helpful?

Solution

recorder.prepare();
Thread.sleep(1000);
recorder.start();

For incoming call it was taking time to prepare.

Hold the prepare for 1 sec and everything is worked fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top