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 5965015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:32:14+00:00 2026-05-22T19:32:14+00:00

enter code here When I try to recording video from camera at version Android

  • 0

enter code hereWhen I try to recording video from camera at version Android 2.2. It has some errors.No one could find the solution. İs there any bug Android MediaRecorder API. How can I solve this.
I got more errors.You can see some of them in picture.
And an error like that:Camera Preview -13
Thanks a lot.

https://i.stack.imgur.com/72lp7.png
recorder.prepare() fails and throws Java.lang.illegalexeption
Here is Code:

package app.raceway.com;

import java.io.File;
import java.io.IOException;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.hardware.Camera;
import android.media.CamcorderProfile;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

public class VideoCapture extends Activity implements  SurfaceHolder.Callback {
    MediaRecorder recorder;
    SurfaceHolder holder;
    public Camera camera;
    File video;
    String filePath;
    boolean recording = false;
      private static final int FRAME_RATE = 15;

      private static final int CIF_WIDTH = 320;

      private static final int CIF_HEIGHT = 240;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);


    recorder = new MediaRecorder();

    setContentView(R.layout.main);

    SurfaceView cameraView = (SurfaceView) findViewById(R.id.cameraView);
    holder = cameraView.getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    String path=Environment.getExternalStorageDirectory().getAbsolutePath()+
    "/video/videocapture_example.mpg4";
    // make sure the directory we plan to store the recording in exists
    File sampleDir = Environment.getExternalStorageDirectory();
    try { 
        video = new File(sampleDir+"/videofile.3gp");
        sampleDir.createNewFile();
          //video = File.createTempFile("videofile", ".3gp", sampleDir);
      } 
      catch (IOException e)
      {
          Log.e("deneme","sdcard access error");

      }
      filePath=video.getAbsolutePath();

}

private void initRecorder() {

    recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);

}
private void prepareRecorder() throws IOException{
    recorder.setCamera(camera);
    recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
    recorder.setOutputFile(filePath);
    recorder.setMaxDuration(50000); // 50 seconds
    recorder.setMaxFileSize(5000000); // Approximately 5 megabytes
try {

} catch (IllegalStateException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}


}



public void onclickSaveVideo(View v) throws IOException {
    if (recording) {
    Toast t=new Toast(getApplicationContext());
    t.makeText(getApplicationContext(), "Video Recording stopped",Toast.LENGTH_SHORT);
    t.show();
        recorder.stop();
        recording = false;

        // Let's initRecorder so we can record again
        initRecorder();     
    } else {
        try {
            prepareRecorder();
            //recorder.prepare();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        recording = true;
        recorder.prepare();
        recorder.start();
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        recorder.stop();
        Toast t=new Toast(getApplicationContext());
        t.makeText(getApplicationContext(), "Video Recording started",Toast.LENGTH_SHORT);
        t.show();
    }
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
    camera=Camera.open();

    try {
        camera.setPreviewDisplay(holder);
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    camera.startPreview();
    camera.unlock();
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {

}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    if (recording) {
        recorder.stop();
        recording = false;
    }
    recorder.release();
    finish();
    camera.release();
}


}
  • 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-22T19:32:15+00:00Added an answer on May 22, 2026 at 7:32 pm

    Emin,

    Based on the image of the logcat output you provide the crash is occuring with the start() method. You will see from the documentation for the start method that prepare() must be called first or else it will throw the IllegalStateException. In your code all the calls the prepare() are commented out?

    EDIT: We sorted things out in the comments below my answer. He was running this code on an emulator and MediaRecorder is not supported by the emulator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing some quick code to try and extract data from an mp3 file
enter code here I have a table on SQL server 2005 with bigint primary
enter code here Hi All, I have a simple windows service application that connects
I let user enter some code in my Flex3 (Flash 10) app and I
I’m having trouble retrieving the YouTube video automatically. Here’s the code. The problem is
enter code here hi. i am trying to implment custom paging in datalist control
I have the following entry in my c:\Oracle\product\11.1.0\network\ADMIN\TNSNAMES.ORA file. enter code here pvtest.world =
Hi All I have the following code: enter code here public class XMPPClient extends
enter code here I have a property file placed in the etc folder. myapplication.properties
There is my problem : enter code here I have a table called test

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.