Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5955645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:08:36+00:00 2026-05-22T18:08:36+00:00

I am writing code for Video Recording function with Media recorder., But it throws

  • 0

I am writing code for Video Recording function with Media recorder., But it throws Io Exception,Illegal State Exception i searched many times in google but no proper explanation for this one my code is

public class Simple extends Activity {
    /** Called when the activity is first created. */
    Button button,button2;
    MediaRecorder recorder;
    Camera camera;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        button=(Button) findViewById(R.id.button1);
        button2=(Button) findViewById(R.id.button2);

    camera=Camera.open();
    Camera.Parameters params = camera.getParameters();
    camera.setParameters(params);


    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub

            Toast.makeText(getBaseContext(), "Video Start", Toast.LENGTH_LONG).show();

            String mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
            mFileName += "/temp.3mp4";

            recorder=new MediaRecorder();


            recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
            recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
            recorder.setVideoFrameRate(10);
            recorder.setVideoSize(200, 300);
            recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
            recorder.setMaxDuration(50000);
            recorder.setMaxFileSize(5000000);
            recorder.setOutputFile(mFileName);
            try {
                recorder.prepare();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Toast.makeText(getBaseContext(),e.toString(), Toast.LENGTH_LONG).show();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Toast.makeText(getBaseContext(),e.toString(), Toast.LENGTH_LONG).show();
            }
            }
    });

    button2.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Toast.makeText(getBaseContext(), "Video Stop", Toast.LENGTH_LONG).show();
            recorder.stop();
        }
    });

}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:08:37+00:00Added an answer on May 22, 2026 at 6:08 pm

    Here is the code for recording video…

    recorder = new MediaRecorder();
            recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
            recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
            mPreview = new Preview(VideoRecorder.this,recorder);
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            setContentView(mPreview);
    
    recorder.start();
    

    and here is the Preview Class….

    class Preview extends SurfaceView implements SurfaceHolder.Callback
    {
        SurfaceHolder mHolder;
        MediaRecorder tempRecorder;
        public Preview(Context context,MediaRecorder recorder) {
            super(context);
            tempRecorder=recorder;
            mHolder=getHolder();
            mHolder.addCallback(this);
            mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
            // TODO Auto-generated constructor stub
        }
    
        public Surface getSurface()
        {
            return mHolder.getSurface();
        }
    
        public void surfaceCreated(SurfaceHolder holder){
            tempRecorder.setOutputFile("/sdcard/recordvideooutput.3gpp");
            tempRecorder.setPreviewDisplay(mHolder.getSurface());
            try{
                tempRecorder.prepare();
            } catch (Exception e) {
                String message = e.getMessage();
                tempRecorder.release();
                tempRecorder = null;
            }
        }
    
        public void surfaceDestroyed(SurfaceHolder holder) 
        {
            if(tempRecorder!=null)
            {
                tempRecorder.release();
                tempRecorder = null;
            }
        }
    
        public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) 
        {
    
        }
    }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've never had much need for writing large quantities of formal pseudo-code but the
i am writing code to play video file in ownservices.m class in a method
I'm writing a VisualC++ program which have code invoke ffmpeg.exe to convert video file.
im writing a video recorder application for mac with cocoa, and have a huge
This problem is about Javascript writing HTML code for video player. I think there
I am sorry for posting a dodgy code! :( But I'm terrible at writing
I am writing video code in an iphone, based on HTML. With the following
I'm writing some code to handle video input from some cameras using DirectShow, so
In most of the videos, I see expert JQuery developers writing complete code for
When writing code do you consciously program defensively to ensure high program quality and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.