Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Camera Server Died and Camera Error - 100

I'm facing Camera error 100 while testing my android application, I have found some topics on StackOverflow but they were not so helpful. I'm searching for a relevant solution to fix the error.

Code that I've written:

mrec = new MediaRecorder();  // Works well

mCamera = Camera.open();
mCamera.unlock();

mrec.setCamera(mCamera);
mrec.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mrec.setAudioSource(MediaRecorder.AudioSource.MIC); 

mrec.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));

mrec.setOutputFile("/sdcard/zzzz.3gp");

mrec.prepare();
mrec.start(); 

Code to record Camera :

protected void startRecordingVideo() throws IOException 
{
camera = Camera.open();
camera.unlock();
SimpleDateFormat timeStampFormat = new SimpleDateFormat(
        "yyyy-MM-dd-HH.mm.ss");
String fileName = "video_" + timeStampFormat.format(new Date())
        + ".3gp";
String fileURL = "/sdcard/"+fileName;
surfaceView = (SurfaceView) findViewById(R.id.surface_camera);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mrec = new MediaRecorder();

mrec.setCamera(camera);

mrec.setPreviewDisplay(surfaceHolder.getSurface());
mrec.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    mrec.setAudioSource(MediaRecorder.AudioSource.MIC); 
    mrec.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_LOW));
    mrec.setPreviewDisplay(surfaceHolder.getSurface());
    mrec.setOutputFile("/sdcard/"+fileName); 

    mrec.prepare();
    mrec.start();
}

protected void stopRecordingVideo() {
mrec.stop();
mrec.release();
camera.release();
}

private void releaseMediaRecorder(){
if (mrec != null) {
    mrec.reset();   // clear recorder configuration
    mrec.release(); // release the recorder object
    mrec = null;
    camera.lock();           
  }
}

private void releaseCamera(){
if (camera != null){
    camera.release();        
    camera = null;
}
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
    int height) {
// TODO Auto-generated method stub
}


@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub

if (camera != null){
    Parameters params = camera.getParameters();
    camera.setParameters(params);
}
else {
    Toast.makeText(getApplicationContext(), "Camera not available!", Toast.LENGTH_LONG).show();
    finish();
}
}


@Override
public void surfaceDestroyed(SurfaceHolder holder) {
releaseMediaRecorder();
camera.stopPreview();
camera.release();


}

Here are the Logcat output :

12-27 17:52:02.788: W/IMediaDeathNotifier(21434): media server died!
12-27 17:52:02.788: W/Camera(21434): Camera server died!
12-27 17:52:02.788: W/Camera(21434): ICamera died
12-27 17:52:03.048: E/Camera(21434): Error 100  
like image 459
Milos Cuculovic Avatar asked Dec 27 '11 17:12

Milos Cuculovic


3 Answers

You need to set the preview display to the recorder.

mrec.setPreviewDisplay(SurfaceHolder.getSurface());

The video data in the preview display acts as the input to the video recorder. Also you need to ensure that the video resolution for the recording and the preview resolution are the same.

like image 115
bluefalcon Avatar answered Oct 17 '22 12:10

bluefalcon


This exception will occur when the camera parameters have not been set prior to use.

Here is a method to set the most common default values. Note that this method uses defaults on the assumption that the camera is being used for still photography. Remove the supported picture formats for video capture.

/**
 * This method configures the camera with a set of defaults for brightness,
 * flash, camera mode, and picture sizes.
 */
private void setCameraDefaults()
{
    Camera.Parameters params = mCamera.getParameters();

    // Supported picture formats (all devices should support JPEG).
    List<Integer> formats = params.getSupportedPictureFormats();

    if (formats.contains(ImageFormat.JPEG))
    {
        params.setPictureFormat(ImageFormat.JPEG);
        params.setJpegQuality(100);
    }
    else
        params.setPictureFormat(PixelFormat.RGB_565);

    // Now the supported picture sizes.
    List<Size> sizes = params.getSupportedPictureSizes();
    Camera.Size size = sizes.get(sizes.size()-1);
    params.setPictureSize(size.width, size.height);

    // Set the brightness to auto.
    params.setWhiteBalance(Camera.Parameters.WHITE_BALANCE_AUTO);

    // Set the flash mode to auto.
    params.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO);

    // Set the scene mode to auto.
    params.setSceneMode(Camera.Parameters.SCENE_MODE_AUTO);

    // Lastly set the focus to auto.
    params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);

    mCamera.setParameters(params);
}
like image 24
Steven Avatar answered Oct 17 '22 11:10

Steven


Here is a sample, camera can works well. Hope help. https://github.com/josnidhin/Android-Camera-Example

like image 1
Daniel Avatar answered Oct 17 '22 10:10

Daniel