hi guys,

I am trying to develop a Simple Video recorder application on Android,
using available media recorder package.

The application throws exception for prepare method.

Below is the code I am using.

package com.ittiam.media;

import java.io.IOException;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.media.MediaRecorder;
import android.media.MediaRecorder.OnInfoListener;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.Window;

package com.ittiam.media;

import java.io.IOException;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.media.MediaRecorder;
import android.media.MediaRecorder.OnInfoListener;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.Window;

public class SimpleVideoRecorder extends Activity implements
OnInfoListener, SurfaceHolder.Callback
{
        public MediaRecorder mMediaRecorder;
        VideoPreview mVideoPreview;
        SurfaceHolder mSurfaceHolder;

        /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_PROGRESS);
        setContentView(R.layout.video_camera);

        mMediaRecorder = new MediaRecorder();

        mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);

        mMediaRecorder.setVideoSource
(MediaRecorder.VideoSource.CAMERA);

        mMediaRecorder.setOutputFormat
(MediaRecorder.OutputFormat.THREE_GPP);

        mMediaRecorder.setMaxDuration(10000);

        mMediaRecorder.setOutputFile("/sdcard/test.3gp");

        mMediaRecorder.setVideoFrameRate(20);

        mMediaRecorder.setVideoSize(352,288);

        mMediaRecorder.setVideoEncoder
(MediaRecorder.VideoEncoder.DEFAULT);

        mMediaRecorder.setAudioEncoder
(MediaRecorder.AudioEncoder.AMR_NB);

        // remaining >= LOW_STORAGE_THRESHOLD at this point, reserve a
quarter
        // of that to make it more likely that recording can complete
successfully.
        try
        {
            mMediaRecorder.setMaxFileSize(10 * 1024 * 1024);
        }
        catch (RuntimeException exception)
        {
            // We are going to ignore failure of setMaxFileSize here,
as
            // a) The composer selected may simply not support it, or
            // b) The underlying media framework may not handle 64-bit
range
            //    on the size restriction.
        }

        try
        {
            float VIDEO_ASPECT_RATIO = 176.0f / 144.0f;
            mVideoPreview = (VideoPreview) findViewById
(R.id.camera_preview);
            mVideoPreview.setAspectRatio(VIDEO_ASPECT_RATIO);

            SurfaceHolder holder = mVideoPreview.getHolder();
            holder.addCallback(this);
            holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
            holder.setFixedSize(352,288);
            //holder.
                mMediaRecorder.setPreviewDisplay(holder.getSurface());
        }
        catch(Throwable e)
        {

        }

        try
        {
            mMediaRecorder.prepare();
        }
        catch (IOException exception)
        {
            releaseMediaRecorder();
        }

        try
        {
                mMediaRecorder.start();
        }
        catch(IllegalStateException e)
        {

        }

    }

    private void releaseMediaRecorder()
    {
        if (mMediaRecorder != null)
        {
            mMediaRecorder.reset();
            mMediaRecorder.release();
            mMediaRecorder = null;
        }
    }
    public void onInfo (MediaRecorder mr, int what, int extra)
    {
        switch(what)
        {
                case MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED:
                {
                        mMediaRecorder.stop();
                        releaseMediaRecorder();
                }
                break;

                case MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED:
                {
                        mMediaRecorder.stop();
                        releaseMediaRecorder();
                }
                break;
                default:
                {
                        mMediaRecorder.stop();
                        releaseMediaRecorder();
                }
        }
        return;
    }

    public void surfaceChanged(SurfaceHolder holder, int format, int
w, int h)
    {
    }

    public void surfaceCreated(SurfaceHolder holder)
    {
        mSurfaceHolder = holder;
    }

    public void surfaceDestroyed(SurfaceHolder holder) {
        mSurfaceHolder = null;
    }

}

Can anyone help me on this?

Thanks in advance!!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to