MediaRecorder failed when i stop the recording
In my case i was using Surface as the VideoSource and i just forget to set Input Surface. and then i got this -1007 error.
And i fixed by giving Input Surface and it worked fine.
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);
Look at the documentation:
Note that a
RuntimeException
is intentionally thrown to the application, if no valid audio/video data has been received whenstop()
is called. This happens ifstop()
is called immediately afterstart()
. 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();
}