MediaRecorder failed when i stop the recording

和自甴很熟 提交于 2019-11-28 10:41:29

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