tags:

views:

460

answers:

3

Hi, I'm new here. I have been trying to create a video capture app using the android emulator without much success. As far as I know and looking through all the samples and code on the internet (this site and others), I must still be missing a step.

I've tried using this sample near the end of this thread made by JonPro: http://www.anddev.org/viewtopic.php?p=24723#24723

and I've tried making my own but the media recorder would always fail on the prepare stage with the most unhelpful message of 'prepare failed'. I have no clue what I am missing. I seem to have the correct permissions and a SDCard is mounted according to the emulator. Should I be using a android SDK version other than 2.1?

Even though the code in that forum claims to work, I figured out that this line was missing: recorder.setCamera(camera);

But still no joy as the logs shows that: 'Failed to get camera(0x16b70) parameters' when prepare() is called but it still doesn't make sense as the preview is okay, but no recording! Any help or suggestions will be appreciated.

Edit: Can anyone confirm that this can work for the SDK and the emulator? or I'm I wasting my time trying to get this to work in this version. Am I able to get the source code for the prepare function as it is OpenSource?

A: 

Hi. I have the same problem and I am using a Nexus, haven't tried in the emulator. Some parts of my code:

private android.hardware.Camera mCameraDevice;

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

    mPreview = (SurfaceView) findViewById(R.id.SurfaceView01);
    mHolder = mPreview.getHolder();
    mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    mHolder.addCallback(this);

    mCameraDevice = Camera.open();
    cameraCreated = true;
    mParameters = mCameraDevice.getParameters();
    mCameraDevice.setParameters(mParameters);

    mCameraDevice.startPreview();
    mMediaRecorder = new MediaRecorder();

    mMediaRecorder.setOnInfoListener(this);
    mMediaRecorder.setOnErrorListener(this);

    mMediaRecorder.setCamera(mCameraDevice);

RecordVideoButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (!getIsRecording()){
                if (!manuelSettingsSet){
                    try {
                        Log.d(LOG_TAG, "Sets up and starts a manual video recording.");
                        parameters.encodeAudio = true;
                        parameters.encodeVideo = true;
                        applyParameters();
                        prepare();
                        start();
                    } catch (IllegalStateException e) {
                        reset();
                        Log.d(LOG_TAG, "reset() IllegalStateException");
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }


 public void surfaceCreated(SurfaceHolder arg0) {
     // TODO Auto-generated method stu1595
        try {
            Log.d(LOG_TAG, "setPreviewDisplay enter");
            mCameraDevice.setPreviewDisplay(mHolder);
            Log.d(LOG_TAG, "setPreviewDisplay exit");
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
     isSurfaceCreated = true;


 }

Why do I get the same failure? Have you fixed it?

P.N
+1  A: 

Hi again. The fix for this problem is mCameraDevice.unlock() must be set before prepare. It's important that this is set after mCameraDevice.setPreviewDisplay(mHolder);

example:

/*--------------------------------------surfaceCreated---------------------------------------------*/
/**
 * Surface Created sets that the surface is created.
 */
 public void surfaceCreated(SurfaceHolder arg0) {
     // TODO Auto-generated method stu1595
        try {
            Log.d(LOG_TAG, "setPreviewDisplay enter");
            mCameraDevice.setPreviewDisplay(mHolder);
            Log.d(LOG_TAG, "setPreviewDisplay exit");
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        mCameraDevice.unlock();
        Log.d("*************", "***********unlock()****");
     isSurfaceCreated = true;


 }

BR P.N

P.N
A: 

From SDK documentation you can see that: Currently, MediaRecorder does not work on the emulator (Android SDK for MediaRecorder class).

I have found one working example (tested on Android 1.6 and 2.2) here - How to use MediaRecorder in Android

sash