android相机错误1001 - 那到底是什么?

时间:2013-01-24 03:45:23

标签: android camera

我在网上搜索过,我无法找出1001错误是什么。几秒钟后,我得到相机100错误,但我无法找出第一个错误是什么。有没有人有任何想法?

4 个答案:

答案 0 :(得分:5)

我在S3上遇到了这个错误。我相信我已经跟踪了MediaRecorder如何使用相机预览表面。在我的情况下,当我尝试开始录制时,预览显示被重置。我通过清理我的代码来解决它,只是使用调用来设置,启动和停止下面的SurfaceView实现中的预览显示(来自Android Camera developer guide):

public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback {
private SurfaceHolder mHolder;
private Camera mCamera;

public CameraPreview(Context context, Camera camera) {
    super(context);
    mCamera = camera;

    // Install a SurfaceHolder.Callback so we get notified when the
    // underlying surface is created and destroyed.
    mHolder = getHolder();
    mHolder.addCallback(this);
    // deprecated setting, but required on Android versions prior to 3.0
    mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}

public void surfaceCreated(SurfaceHolder holder) {
    // The Surface has been created, now tell the camera where to draw the preview.
    try {
        mCamera.setPreviewDisplay(holder);
        mCamera.startPreview();
    } catch (IOException e) {
        Log.d(TAG, "Error setting camera preview: " + e.getMessage());
    }
}

public void surfaceDestroyed(SurfaceHolder holder) {
    // empty. Take care of releasing the Camera preview in your activity.
}

public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
    // If your preview can change or rotate, take care of those events here.
    // Make sure to stop the preview before resizing or reformatting it.

    if (mHolder.getSurface() == null){
      // preview surface does not exist
      return;
    }

    // stop preview before making changes
    try {
        mCamera.stopPreview();
    } catch (Exception e){
      // ignore: tried to stop a non-existent preview
    }

    // set preview size and make any resize, rotate or
    // reformatting changes here

    // start preview with new settings
    try {
        mCamera.setPreviewDisplay(mHolder);
        mCamera.startPreview();

    } catch (Exception e){
        Log.d(TAG, "Error starting camera preview: " + e.getMessage());
    }
}
}

答案 1 :(得分:3)

以为我会在这里添加帖子以供将来参考。这个问题困扰了我很长一段时间。 事实证明我的问题是由不正确的预览大小引起的,尽管分辨率集是从getSupportedPictureSize方法获得的。

例如,您可以按如下方式获取尺寸:

//first entry in list is 1392x1392 for front facing camera on an S3
List<Camera.Size> supportedPictureSizes = params.getSupportedPictureSizes();

设置此分辨率或忽略全部设置图片大小将导致可怕的错误1001.

如果您在任何其他设备上遇到此问题,我建议尝试不同的图片尺寸。

答案 2 :(得分:0)

所以还有另一个原因让我在Galaxy S3上得到它。我使用TextureView来显示我的相机预览,并在成功预览后按下主页按钮然后再次进入应用程序时遇到了这个可怕的错误。在onResume()函数中,我再次启动预览,发现我没有在onSurfaceTextureDestroyed()函数中释放SurfaceTexture实例变量。

我在此功能中添加了发布行,它现在看起来像这样,效果很好:

@Override public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
    mSurfaceTexture = null; //This was the offending culprit.

    releaseMediaPlayer();
    releaseVideoRecorder();
    releaseCamera();

    return false;
}

答案 3 :(得分:0)

在我的情况下,在Samsung S3中,未设置video-size参数,这导致1001错误。使用预览尺寸在媒体记录器上设置视频大小可解决问题。但是,此更改可能会在其他设备上失败,因为参数可能在所有设备中可用或未设置。以下代码解决了大多数设备:

if(params.get("video-size") != null && params.get("video-size").isEmpty()) {
    int videoWidth = params.getPreviewSize().width;
    int videoHeight = params.getPreviewSize().height;
    mediaRecorder.setVideoSize(videoWidth, videoHeight);
} else {
    mediaRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
}