I'm trying to build a simple video recorder for an Android device and I've had limited success and mixed results. It worked once, but now, without changing anything, I'm getting a "Camera is not available" error followed by "prepare failed -2147483648" error
The constructor for the previewer looks like
private SurfaceHolder holder_;
private MediaRecorder r_;
public CameraPreview(Context context, AttributeSet attrs) {
super(context, attrs);
holder_ = getHolder();
holder_.addCallback(this);
holder_.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
r_ = new MediaRecorder();
r_.setAudioSource(MediaRecorder.AudioSource.MIC);
r_.setVideoSource(MediaRecorder.VideoSource.CAMERA);
r_.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
r_.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
r_.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
}
And my
surfaceCreated()
method looks like
@Override
public void surfaceCreated(SurfaceHolder holder) {
r_.setPreviewDisplay(holder_.getSurface());
r_.setOutputFile("/sdcard/test.mpg");
if (r_ != null){
try{
r_.prepare();
r_.start();
}catch(Exception e){
e.printStackTrace();
}
}
}
Any thoughts?
Thanks, Chris