MediaRecorder failed when i stop the recording MediaRecorder failed when i stop the recording android android

MediaRecorder failed when i stop the recording


Look at the documentation:

Note that a RuntimeException is intentionally thrown to the application, if no valid audio/video data has been received when stop() is called. This happens if stop() is called immediately after start(). The failure lets the application take action accordingly to clean up the output file (delete the output file, for instance), since the output file is not properly constructed when this happens.

In other words: Dalvik throws the exception on purpose. You have to handle it to clean up after your app. You'd have to handle it like this:

private void stopRecording() {    try {        recorder.stop();    } catch(RuntimeException stopException) {        // handle cleanup here    }    camera.lock();}


I had a similar error -1007 when I was recording audio with AMR_WB, but it turned out that the problem was that I forgot to set sampling rate.

mediaRecorder.setAudioSamplingRate(16000);