我在测试我的Android应用程序时遇到了Camera error 100,我在StackOverflow
找到了一些主题,但它们并没有那么有用。我正在寻找解决错误的相关解决方案。
我写过的代码:
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();
记录相机的代码:
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();
}
以下是Logcat输出:
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
答案 0 :(得分:6)
您需要将预览显示设置为录像机。
mrec.setPreviewDisplay(SurfaceHolder.getSurface());
预览显示中的视频数据充当录像机的输入。您还需要确保录制的视频分辨率和预览分辨率相同。
答案 1 :(得分:3)
如果在使用前未设置相机参数,则会发生此异常。
以下是设置最常用默认值的方法。请注意,此方法使用默认值,假设相机正用于静态拍摄。删除支持的视频捕获图片格式。
/**
* 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);
}
答案 2 :(得分:1)
这是一个示例,相机可以很好地工作。希望有所帮助 https://github.com/josnidhin/Android-Camera-Example
答案 3 :(得分:0)
使用在相机服务器出现故障时触发的Camera.ErrorCallback。 Camera.ErrorCallback Android documentation 然后,您可以检查那里的相机属性。