Is it correct to call start() when prepare() failed on MediaRecorder object?

294 views Asked by At

From this code snippet of the android developer website.

Is it not wrong to call mRecorder.start() even if mRecorder.prepare() has failed?

private void startRecording() {
    mRecorder = new MediaRecorder();
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    mRecorder.setOutputFile(mFileName);
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

    try {
        mRecorder.prepare();
    } catch (IOException e) {
        Log.e(LOG_TAG, "prepare() failed");
    }

    mRecorder.start();
}
1

There are 1 answers

0
Strider On BEST ANSWER

Yes, it is wrong.

public void start () Added in API level 1

Begins capturing and encoding data to the file specified with setOutputFile(). Call this after prepare(). Since API level 13, if applications set a camera via setCamera(Camera), the apps can use the camera after this method call. The apps do not need to lock the camera again. However, if this method fails, the apps should still lock the camera back. The apps should not start another recording session during recording.

Throws IllegalStateException if it is called before prepare().

More info here