Juan A. Doval
Juan A. Doval

Reputation: 131

MediaRecorder start failed -19 and Camera error 100

I am developing an app to record video.

I got this code in my App which is running fine in Nexus 4 and Sony Ericsson mini pro, but when I test in other devices, like Archos 80G9 and Jiayu G3ST, the app gives me the following error

"MediaRecorder start failed -19"

or sometimes

"camera error 100 ".

I tried implementing some changes suggested in other stackoverflow posts but the error still appears.

private boolean prepareVideoRecorder() {
    /** ADDED Sony Ericsson Stoped */
    try {
        mCamera.setPreviewDisplay(null);
    } catch (java.io.IOException ioe) {
        Log.d(TAG,
                    "IOException nullifying preview display: "
                            + ioe.getMessage());
    }
    mCamera.stopPreview();

    mMediaRecorder = new MediaRecorder();
    // Step 1: Unlock and set camera to MediaRecorder
    mCamera.unlock();
    mMediaRecorder.setCamera(mCamera);

    // Step 2: Set sources
    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    // Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
    CameraBackFront cm = new CameraBackFront();
    int id = cm.getBackCameraId();
    if (qualityString().equalsIgnoreCase("Low")) {
        mMediaRecorder.setProfile(CamcorderProfile.get(id,
                    CamcorderProfile.QUALITY_LOW));
    } else if (qualityString().equalsIgnoreCase("High")) {
        mMediaRecorder.setProfile(CamcorderProfile.get(id,
                    CamcorderProfile.QUALITY_HIGH));
    } else if (qualityString().equalsIgnoreCase("480p")) {
        mMediaRecorder.setProfile(CamcorderProfile.get(id,
                    CamcorderProfile.QUALITY_480P));
    } else if (qualityString().equalsIgnoreCase("720p")) {
        mMediaRecorder.setProfile(CamcorderProfile.get(id,
                    CamcorderProfile.QUALITY_720P));
    } else if (qualityString().equalsIgnoreCase("1080p")) {
        try {
            mMediaRecorder.setProfile(CamcorderProfile.get(id,
                        CamcorderProfile.QUALITY_1080P));
        } catch (Exception e) {
            mMediaRecorder.setProfile(CamcorderProfile.get(id,
                        CamcorderProfile.QUALITY_HIGH));
        }
    } else {
        mMediaRecorder.setProfile(CamcorderProfile.get(0,
                    CamcorderProfile.QUALITY_HIGH));
    }

    // Step 4: Set output file
    mMediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO)
                .toString());
    /** ADD FILE NAME */
    addFileNameDB();
    // Step 5: Set the preview output
    mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());

    // Step 6: Prepare configured MediaRecorder
    try {
        mMediaRecorder.prepare();
    } catch (IllegalStateException e) {
        Log.d(TAG,
                    "IllegalStateException preparing MediaRecorder: "
                            + e.getMessage());
        releaseMediaRecorder();
        return false;
    } catch (IOException e) {
        Log.d(TAG, "IOException preparing MediaRecorder: " + e.getMessage());
        releaseMediaRecorder();
        return false;
    }

    return true;
}

I have tried:

Upvotes: 3

Views: 3003

Answers (1)

Juan A. Doval
Juan A. Doval

Reputation: 131

Finally i fix my problem using

...
releaseCamera();
if(prepareVideoRecorder){
   ...
}

before prepareVideoRecorder().

and into prepareVideoRecorder add a new instance of camera.

public void prepareVideoRecorder(){
   mCamera = getCameraInstance();
   ...
}

With this things i have fixed:

  • MediaRecorder start failed -19.
  • Camera Error 100 (media server died and camera died ).

Upvotes: 1

Related Questions