开发者

Exception gets thrown while recording with the camera

开发者 https://www.devze.com 2023-03-14 09:49 出处:网络
When the camera start to record my application throws this exception: E/MediaRecorder( 3316): setOutputFile called in an invalid state(2):

When the camera start to record my application throws this exception:

E/MediaRecorder( 3316): setOutputFile called in an invalid state(2):
E/AndroidRuntime( 3316): java.lang.IllegalStateException
E/AndroidRuntime( 3316):        at android.media.MediaRecorder._setOutputFile(Native Method)
E/AndroidRuntime( 3316):        at android.media.MediaRecorder.prepare(MediaRecorder.java:542)
E/AndroidRuntime( 3316):        at com.android.cameradiag.VideoCamera.initializeRecorder(VideoCamera.java:448)
E/AndroidRuntime( 3316):        at com.android.cameradiag.VideoCamera.startVideoRecording(VideoCamera.java:638)

My code is:

mMediaRecorder = new MediaRecorder();

// Unlock the camera object before passing it to media recorder.
mCameraDevice.unlock();
mMediaRecorder.setCamera(mCameraDevice);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
// mMediaRecorder.setProfile(mProfile);
mMediaRecorder.setMaxDuration(mMaxVideoDurationInMs);

// Set output file.
if (mStorageStatus != STORAGE_STATUS_OK) {
    mMediaRecorder.setOutputFile("/dev/null");
} else {
    // Try Uri in the intent first. If it doesn't exist, use our own
    // instead.

    createVideoPath();
    mMediaRecorder.setOutputFile(mVideoFilename);

}

mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
try {
    mMediaRecorder.prepare();
} catch (IOException e) {
    Log.e(TAG, "prepare failed for " + mVideoFilename, e);
    releaseMediaRecorder();
    throw new RuntimeException(e);
}

I found the recorded 3gp file exists on the SDCard but it has a s开发者_JS百科ize of 0 bytes.


Before using mMediaRecorder.setOutputFile(mVideoFilename); you have to set the output format.

See the flowchart on MediaRecorder.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号