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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:07:28+00:00 2026-05-23T01:07:28+00:00

I’m having some errors with my custom recording application using android. I saw most

  • 0

I’m having some errors with my custom recording application using android. I saw most of this code from a book called PRO Android Media. I developed the app using sdk "8" version. However, I am testing the phone on my htc evo 4g which just got updated to gingerbread. So I dont know how much that would have changed. Anyways my app still wasnt working when i tested it on 2.2 version either.

Here is the code below

package com.apapa.vrsixty;

import java.io.File;
import java.io.IOException;
import android.R.string;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;

import android.media.CamcorderProfile;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
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 record extends Activity implements OnClickListener, SurfaceHolder.Callback{
    
    MediaRecorder recorder;
    SurfaceHolder holder;
    boolean recording=false;
    public static final String TAG = "VIDEOCAPTURE";
    /** Called when the activity is first created. */
    @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_PORTRAIT);

        recorder = new MediaRecorder();// Instantiate our media recording object
        initRecorder();
        setContentView(R.layout.view);
        
        SurfaceView cameraView = (SurfaceView) findViewById(R.id.surface_view);
        holder = cameraView.getHolder();
        holder.addCallback(this);
        holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

        cameraView.setClickable(true);// make the surface view clickable
        cameraView.setOnClickListener((OnClickListener) this);// onClicklistener to be called when the surface view is clicked
    }

    private void initRecorder() {// this takes care of all the mediarecorder settings
        File OutputFile = new File(Environment.getExternalStorageDirectory().getPath());
        String video= "/DCIM/100MEDIA/Video";
        CamcorderProfile cpHigh = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
         recorder.setProfile(cpHigh);        
       
        //recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
        // default microphone to be used for audio
       // recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);// default camera to be used for video capture.
        recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);// generally used also includes h264 and best for flash
       // recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); //well known video codec used by many including for flash
        //recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);// typically amr_nb is the only codec for mobile phones so...
              
        //recorder.setVideoFrameRate(15);// typically 12-15 best for normal use. For 1080p usually 30fms is used.
       // recorder.setVideoSize(720,480);// best size for resolution.
        //recorder.setMaxFileSize(10000000);
        recorder.setOutputFile(OutputFile.getAbsolutePath()+video+".3gp");
        //recorder.setVideoEncodingBitRate(256000);//
        //recorder.setAudioEncodingBitRate(8000);
       recorder.setMaxDuration(600000);
       
        
    }

    /*if(record.setMaxDuration>60000){
        
        recorder.stop();
        MediaRecorder.OnInfoListener;
        Toast display = Toast.makeText(this, "You have exceeded the record time", Toast.LENGTH_SHORT);// toast shows a display of little sorts
        display.show();
        return true;
    }*/

    private void prepareRecorder() {
        recorder.setPreviewDisplay(holder.getSurface());

        try {
            recorder.prepare();
        } catch (IllegalStateException e) {
            e.printStackTrace();
            finish();
        } catch (IOException e) {
            e.printStackTrace();
            finish();
        }
    }

    public void onClick(View v) {
        if (recording) {
            recorder.stop();
            recording = false;

            // Let's initRecorder so we can record again
            initRecorder();
            prepareRecorder();
            Toast display = Toast.makeText(this, "Stopped Recording", Toast.LENGTH_SHORT);// toast shows a display of little sorts
            display.show();
            
        
        } else {
            
            recorder.start();
            Log.v(TAG,"Recording Started"); 
            recording = true;
            
        }
    }

    public void surfaceCreated(SurfaceHolder holder) {
        initRecorder();
        Log.v(TAG,"surfaceCreated");
        prepareRecorder();
    }
    
    public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {
    }

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

Its bringing up these errors.

06-09 13:37:52.833: ERROR/AndroidRuntime(27979): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.apapa.vrsixty/com.apapa.vrsixty.record}: java.lang.IllegalStateException
06-09 13:37:52.833: ERROR/AndroidRuntime(27979):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1821)
06-09 13:37:52.833: ERROR/AndroidRuntime(27979):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1842)
06-09 13:37:52.833: ERROR/AndroidRuntime(27979):     at android.app.ActivityThread.access$1500(ActivityThread.java:132)
06-09 13:37:52.833: ERROR/AndroidRuntime(27979):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
06-09 13:37:52.833: ERROR/AndroidRuntime(27979):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-09 13:37:52.833: ERROR/AndroidRuntime(27979):     at android.os.Looper.loop(Looper.java:143)
06-09 13:37:52.833: ERROR/AndroidRuntime(27979):     at android.app.ActivityThread.main(ActivityThread.java:4263)
06-09 13:37:52.833: ERROR/AndroidRuntime(27979):     at java.lang.reflect.Method.invokeNative(Native Method)
06-09 13:37:52.833: ERROR/AndroidRuntime(27979):     at java.lang.reflect.Method.invoke(Method.java:507)
06-09 13:37:52.833: ERROR/AndroidRuntime(27979):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-09 13:37:52.833: ERROR/AndroidRuntime(27979):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-09 13:37:52.833: ERROR/AndroidRuntime(27979):     at dalvik.system.NativeStart.main(Native Method)
06-09 13:37:52.833: ERROR/AndroidRuntime(27979): Caused by: java.lang.IllegalStateException
06-09 13:37:52.833: ERROR/AndroidRuntime(27979):     at android.media.MediaRecorder.setOutputFormat(Native Method)
06-09 13:37:52.833: ERROR/AndroidRuntime(27979):     at android.media.MediaRecorder.setProfile(MediaRecorder.java:293)
06-09 13:37:52.833: ERROR/AndroidRuntime(27979):     at com.apapa.vrsixty.record.initRecorder(record.java:67)
06-09 13:37:52.833: ERROR/AndroidRuntime(27979):     at com.apapa.vrsixty.record.onCreate(record.java:50)
06-09 13:37:52.833: ERROR/AndroidRuntime(27979):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
06-09 13:37:52.833: ERROR/AndroidRuntime(27979):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1785)

Please any help will suffice please. I just cant wait to see an actually recording in stead of "The application has stopped unexpectedly."

Update:

Well thanks, recorder.reset(); worked for me but I am having an issue when I start the recorder. I have to click on my phone before it actually shows the preview. Also, how do i make the recorder show numbers in a countdown when the video starts recording? The video doesn’t save to my sd card even though i include

recorder.OutPutFile("/sdcard/video.mp4");

And I have the permission WRITE_EXTERNAL_STORAGE in my manifest file.

Another question is how do i save the video in an incrememntal manner. For example, the first video that i record saves as "video1", the second video is "video2" and so on and so forth. I will appreciate any help that I can get with this issue thank you.

  • 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-23T01:07:28+00:00Added an answer on May 23, 2026 at 1:07 am

    Do you have the permission set in AndroidManifest.xml?

    <uses-permission android:name="android.permission.CAMERA"></uses-permission>
    

    Also I have had issues like this before try calling:

    recorder.reset();

    at the start of your initRecorder() method.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites 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.