MediaRecorder: start failed

三世轮回 提交于 2019-12-02 02:57:12

问题


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..


回答1:


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.



来源:https://stackoverflow.com/questions/21960117/mediarecorder-start-failed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!