Mediarecorder Start Failed: -38

MediaRecorder gives start error or IllegalStateException

The problem is that you're not setting the camera, using Camera 1 API you should first open the camera, then unlock it and set it to the recorder. Only after that you can continue with the configuration of MediaRecorder (which is btw a very beautifully written piece of API)

MediaRecorder recorder = new MediaRecorder();

Camera camera = Camera.open();
camera.unlock();
recorder.setCamera(camera);
recorder.setPreviewDisplay(surfaceHolder.getSurface());

recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);

recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);

File file = getAlbumDir();
recorder.setOutputFile(file.getAbsolutePath());

recorder.setMaxDuration(50000);
recorder.setMaxFileSize(5000000);
try {
recorder.prepare();
recorder.start();
} catch (IllegalStateException | IOException e) {
e.printStackTrace();
}

MediaRecorder Start Failed Error

code 2147483648 refers to MEDIA_ERROR_SYSTEM (low-level system error).

Based on the documentation:

A BroadcastReceiver object is only valid for the duration of the call
to onReceive(Context, Intent). Once your code returns from this
function, the system considers the object to be finished and no longer
active.

In other words, the MediaRecorder instance that you expect to be there might actually not exist anymore since you're within a different BroadcastReceiver instance than the one that created the MediaRecorder. Its not a great idea to perform this task in BroadcastReceiver since it will only execute for 10 seconds after which System could declare app as not responding.

One solution would be to execute this code to Service

Android Media Recording: java.lang.RuntimeException: start failed

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);

or other sources.

also you can remove FC by change recorderstart() to try/catch with IllegalStateException,Exception same as this

        try {
recorder.prepare();

} catch (IllegalStateException e) {
// TODO Auto-generated catch block
Log.d("ERROR ","IllegalStateException");
} catch (Exception e) {
// TODO Auto-generated catch block
Log.d("ERROR ","IOException");
e.printStackTrace();
}
try {
recorder.start();
} catch (Exception e) {

}

i had this problem my self,this is working great for call recording but having problem with receiver voice quality is very low if you find solution of this tel me too.



Related Topics



Leave a reply



Submit