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

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(); }

--------------Solutions-------------

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

Category:android Time:2018-12-19 Views:2

Related post

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 3.250 (s). 13 q(s)