Prabha Karan
Prabha Karan

Reputation: 1319

The application crashes when the media recorder starts?

I am using the media recorder to record the calls in android. Some times the mediaRecorder is recording audio and some times it doesn't record audio. When we play the recorded audio The error shown as "The player doesn't supports this type of audio file ".

The below code is for the recording the audio

 try {
                    f1 = File.createTempFile("Sound", ".mp3", dir);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                fileName = f1.getName();
                mediaRecorder = new MediaRecorder();
                mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
                mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
                mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
                mediaRecorder.setOutputFile(f1.getAbsolutePath());
                try {
                    mediaRecorder.prepare();
                } catch (IllegalStateException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                mediaRecorder.start();
                recordstarted = true;

My logcat error shown below

 E/MediaRecorder: start failed: -38
07-03 11:10:23.718 8558-8558/com.seyali.callLog E/UncaughtException: java.lang.RuntimeException: Unable to start receiver com.seyali.callLog.receiver.CallReceiver: java.lang.IllegalStateException
                                                                         at android.app.ActivityThread.handleReceiver(ActivityThread.java:2593)
                                                                         at android.app.ActivityThread.access$1700(ActivityThread.java:139)
                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1369)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                         at android.os.Looper.loop(Looper.java:149)
                                                                         at android.app.ActivityThread.main(ActivityThread.java:5257)
                                                                         at java.lang.reflect.Method.invokeNative(Native Method)
                                                                         at java.lang.reflect.Method.invoke(Method.java:515)
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
                                                                         at dalvik.system.NativeStart.main(Native Method)
                                                                      Caused by: java.lang.IllegalStateException
                                                                         at android.media.MediaRecorder.start(Native Method)
                                                                         at com.seyali.callLog.receiver.CallReceiver.onReceive(CallReceiver.java:175)
                                                                         at android.app.ActivityThread.handleReceiver(ActivityThread.java:2586)
                                                                         at android.app.ActivityThread.access$1700(ActivityThread.java:139) 
                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1369) 
                                                                         at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                         at android.os.Looper.loop(Looper.java:149) 
                                                                         at android.app.ActivityThread.main(ActivityThread.java:5257) 
                                                                         at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                         at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) 
                                                                         at dalvik.system.NativeStart.main(Native Method) 

Please help me how to solve this.

Upvotes: 1

Views: 1291

Answers (1)

Abdullah Tellioglu
Abdullah Tellioglu

Reputation: 1474

Illegal state means that your media recorder is not ready to recording. There might be several reasons for it. First of all, make sure you can reach the file which you want to play. If it is fine, checkout the media recorder diagram for which state you should play. https://developer.android.com/reference/android/media/MediaRecorder.html


Also, what happens if mediaRecorder.prepare() ? You should put mediaRecorder.start() into the try block.

Upvotes: 2

Related Questions