2

I create the application like this:

The code for beginning recording

public static void startRecording() {

if (recordTime == 0) {
if (null == mr) {
mr = new MediaRecorder();
}
path = new File(Environment.getExternalStorageDirectory(),
"myRecording.3gp");
mr.reset();

Get the ΪMicphone music volime

mr.setAudioSource(MediaRecorder.AudioSource.MIC);
mr.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mr.setOutputFile(path.getAbsolutePath());
mr.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

try {
mr.prepare();
} catch (IOException e) {
}
mr.start();
Record.recordTime = 1;
}
}

End recording

public static void stopRecording() {
if (mr != null) {
// mr.reset();
mr.stop();
mr.release();
mr = null;
Record.recordTime = 0;
}

}

I repeated fast call recording I call the recording fast repeatedly and stop the recording process, it will appear ANR phenomenon. Who knows what the problem is?
Thanks in advance!

4

1 回答 1

4

Well... this post is a little old, but since i am with a very similar case, the explanation of the problem posted here makes sense to me.

When you stop the recording, the video will be saved on the phone memory (internal or SD Card). Since this is an heavy I/O operation, the application may not respond for some time, causing the ANR.

I don't know, but have you tried to put the stop on a different thread ? This may work for you.

    public static void stopRecording() {
    if (mr != null) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                mr.stop();
                mr.release();
                mr = null;
                Record.recordTime = 0;
            }
        }).start();
    }
}
于 2013-10-09T19:03:40.487 回答