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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:19:32+00:00 2026-06-05T11:19:32+00:00

I am using Video Recording in my Android Application. It works fine in Android2.2

  • 0

I am using Video Recording in my Android Application. It works fine in Android2.2 and Android2.3 devices but the application is crashing in Android4.0 .

Here is my code:

  class VideoPreview extends SurfaceView implements SurfaceHolder.Callback
  {
  MediaRecorder recorder;
  SurfaceHolder holder = null; 
  FileOutputStream fileout; 
 public VideoPreview(Context context,MediaRecorder temprecorder) {
 super(context);
    recorder= temprecorder;
    holder= getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
   }
  public void surfaceCreated(SurfaceHolder holder){
    }
  public void surfaceDestroyed(SurfaceHolder holder)
  {
      if(recorder!=null)
      {
    recorder.release();
    Log.d("Video Preview", "Exception1");
    recorder = null;
      }
  }

  //surfaceChanged : This method is called after the surface is created.
  public void surfaceChanged(SurfaceHolder holder, int format, int w, int h)
  {
  }
  public void  stop(){

      if(recorder!=null)
      {
      recorder.release();
      recorder = null;
      }        
  }
    @Override 
    public boolean onKeyDown (int keyCode, KeyEvent event){ 

         return false; 

    } 

  public boolean start()  {     
      String state = android.os.Environment.getExternalStorageState(); 
      String path = Environment.getExternalStorageDirectory().getAbsolutePath() +"/myvideo.mp4";
      File fname = new File(path);
      if (!state.equals(Environment.MEDIA_MOUNTED)) return false;
      File directory = new File(path).getParentFile(); 
      if(!directory.exists() && !directory.mkdirs())   return false; 

          if (recorder == null)    
            recorder = new MediaRecorder();         

           int out_format = MediaRecorder.OutputFormat.MPEG_4;
           //THREE_GPP;
          recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);    
          recorder.setAudioSource(MediaRecorder.AudioSource.MIC); 
            recorder.setOutputFormat(out_format); 
            recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
            recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
            //recorder.setMaxDuration(20000); 
            //recorder.setVideoSize(352,288);   // 352, 288 m_recorder.setVideoSize(320, 240); 176,144
            recorder.setVideoFrameRate(15);
            recorder.setOutputFile(fname.getPath());                
           /* videoview = (VideoView) findViewById(R.id.videosurface);
            SurfaceHolder holder = videoview.getHolder();
            mediarecorder.setPreviewDisplay(holder.getSurface());*/             
            recorder.setPreviewDisplay(holder.getSurface());
            try {
                Thread.sleep(6000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if (!Recorder_Prepare())
            return false;
            else
            return true;
      }    

private boolean Recorder_Prepare()
    {

        try {
            if (recorder != null){
            recorder.prepare();
            Log.d("Video Preview", "Exception2");
            recorder.start();     
            Log.d("Video Preview", "Exception3");
            }
        }
            catch (IllegalStateException e) {
                return false;
            }
            catch (IOException e) { 
                return false;
            }
            return true;            
    }             
  }

Here is my logcat throws exception at recorder.start(); as below:

      06-11 13:54:54.926: E/MediaRecorder(22582): start failed: -19
      06-11 13:54:54.961: E/AndroidRuntime(22582): FATAL EXCEPTION: Thread-2201
      06-11 13:54:54.961: E/AndroidRuntime(22582): java.lang.RuntimeException: start failed.
      06-11 13:54:54.961: E/AndroidRuntime(22582):  at android.media.MediaRecorder.start(Native Method)
      06-11 13:54:54.961: E/AndroidRuntime(22582):  at  com.Myapp.VideoPreview.Recorder_Prepare(VideoPreview.java:106)
      06-11 13:54:54.961: E/AndroidRuntime(22582):  at com.Myapp.VideoPreview.start(VideoPreview.java:94)
      06-11 13:54:54.961: E/AndroidRuntime(22582):  at com.Myapp.videoRecord$1.run(videoRecord.java:94)
      06-11 13:54:54.961: E/AndroidRuntime(22582):  at java.lang.Thread.run(Thread.java:856)

I verfied the application in Samsung Nexus S and it does not have SDCard Support. I googled to solve the problem for 4 hours but cant found the solution. Are there any deprecated methods in the above program? Please help me to resolve the problem.

  • 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-06-05T11:19:33+00:00Added an answer on June 5, 2026 at 11:19 am

    Android 4.0 introduces new runtime checks to make sure you aren’t doing something silly like accessing the network on the main thread.

    Are you doing something silly like accessing the network on the main thread? Is your media being streamed over the network, and where are you calling your VideoPreview.start() method from?

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

Sidebar

Related Questions

In my android application i am recording video using Media recorder.I would like to
I am developing an Android Application for Video Recording. Here I my Android Device
I am using HTML5 Video with this code: <div id=lightBox1 class=lightBox> <video id=video controls
I want to upload video using uploadify newest version, but I failed. My code:
I am using the media recorder class for recording video, I initialize the recorder
I have a situation where I am using SurfaceView fro recording an Video. But
I am using UIImagePickerController for recording video in one of my application. i have
i am recording video from webcam using DirectshowLib2005.dll in C#.net..i have this code to
My basic requirement is to capture video using UIImagePickerController. The recording of video should
My Goal is to capture Video using Android Camera and Record Voice from Mic.

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.