Unable to record video in android app on Motorola Droid Device
<p>I am developing an application with funactionality as recording video through Customize Recording screen, starts recording on button click and stops recording on the same button click and then upload videos to the server. All these things are working on every device as Samsung Galaxy S2, Spice, Samsung Galaxy S+ and one other Samsung Device also but the problem is User are unable to record any video on Motorola Droid. I don't know why. Please check my code of recording video and suggest me any solution regarding that.</p>

<p><strong>Code:</strong></p>

<pre><code>import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.text.Format;
import java.util.ArrayList;

import org.w3c.dom.NodeList;

import com.irant.a1techno.AfterLoginHome;
import com.irant.a1techno.CameraPlay;
import com.irant.a1techno.IRantActivity;
import com.irant.a1techno.R;
import com.irant.utility.ClientHttpRequest;
import com.irant.webserivce.Webconstant;
import com.irant.webserivce.Webserivce;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.hardware.Camera;
import android.media.CamcorderProfile;
import android.media.MediaRecorder;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.Toast;

public class Videocapture extends Activity implements  OnClickListener{

    private Camera myCamera;
    private MyCameraSurfaceView myCameraSurfaceView;
    private MediaRecorder mediaRecorder;

    ProgressDialog progressDialog;
    ///by aditya
    public static String result = "";
    ImageButton myButton;
    SurfaceHolder surfaceHolder;
    boolean recording;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.customvideocamrecord);
        recording = false;

       setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        //Get Camera for preview

       try {
           myCamera = getCameraInstance();
           if(myCamera == null){
            Toast.makeText(Videocapture.this, 
                    "Fail to get Camera", 
                    Toast.LENGTH_LONG).show();
           }

           myCameraSurfaceView = new MyCameraSurfaceView(this, myCamera);
           FrameLayout myCameraPreview = (FrameLayout)findViewById(R.id.videoview);
           myCameraPreview.addView(myCameraSurfaceView);

           myButton = (ImageButton)findViewById(R.id.btn_cameraClick);
           myButton.setOnClickListener(this);
           myCamera.setDisplayOrientation(90);
    } catch (Exception e) {
        // TODO: handle exception
    }


    }



    ////by aditya


    class UploadVedioAsyncTask extends AsyncTask&lt;String, Void, Void&gt; {

        private final ProgressDialog dialog = new ProgressDialog(Videocapture.this);

        // can use UI thread here
        protected void onPreExecute()
        {
            this.dialog.setMessage(Webconstant._strUPLOADVEDIO);
            this.dialog.show();
        }

        // automatically done on worker thread (separate from UI thread)
        protected Void doInBackground(final String... args) {
            //"video uploaded successfully."

            result = Webserivce.doUploadVedio();
            System.out.println("Response :: " + result);
            this.dialog.dismiss();
            return null;
        }

        // can use UI thread here
        protected void onPostExecute(final Void unused) {
            this.dialog.dismiss();
            if(result.equalsIgnoreCase("video uploaded successfully."))
            {
            callDialog();
            }
        }
    }

    public void callDialog() {
        // TODO Auto-generated method stub
        new AlertDialog.Builder(this)
        .setMessage("Video Uploaded successfully") 
        .setNegativeButton("Uploaded",new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        })
        .show();
    }

    private Camera getCameraInstance(){
        // TODO Auto-generated method stub
        Camera c = null;
        try {

            c = Camera.open(); 
            // attempt to get a Camera instance
        }
        catch (Exception e){
            // Camera is not available (in use or does not exist)
        }
        return c; // returns null if camera is unavailable
    }

    @TargetApi(9)
    private boolean prepareMediaRecorder(){
        myCamera = getCameraInstance();
        mediaRecorder = new MediaRecorder();

        myCamera.unlock();
        mediaRecorder.setCamera(myCamera);
       // mediaRecorder.setOrientationHint(90);
       // mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
        mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        //mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
        mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
        mediaRecorder.setOutputFile("/sdcard/myvideo.mp4");
        mediaRecorder.setMaxDuration(60000); // Set max duration 60 sec.
        mediaRecorder.setMaxFileSize(5000000); // Set max file size 5M
        mediaRecorder.setPreviewDisplay(myCameraSurfaceView.getHolder().getSurface());
        try {
            mediaRecorder.prepare();
        } catch (IllegalStateException e) {
            releaseMediaRecorder();
            return false;
        } catch (IOException e) {
            releaseMediaRecorder();
            return false;
        }
        return true;

    }

    @Override
    protected void onPause() {
        super.onPause();
        releaseMediaRecorder();       // if you are using MediaRecorder, release it first
        releaseCamera();              // release the camera immediately on pause event
    }

    private void releaseMediaRecorder(){
        if (mediaRecorder != null) {
            mediaRecorder.reset();   // clear recorder configuration
            mediaRecorder.release(); // release the recorder object
            mediaRecorder = null;
            myCamera.lock();           // lock camera for later use
        }
    }

    private void releaseCamera(){
        if (myCamera != null){
            myCamera.release();        // release the camera for other applications
            myCamera = null;
        }
    }

    public class MyCameraSurfaceView extends SurfaceView implements SurfaceHolder.Callback{

        private SurfaceHolder mHolder;
        private Camera mCamera;

        public MyCameraSurfaceView(Context context, Camera camera) {
            super(context);
            mCamera = camera;

              mCamera.setDisplayOrientation(90);
            // Install a SurfaceHolder.Callback so we get notified when the
            // underlying surface is created and destroyed.
            mHolder = getHolder();
            mHolder.addCallback(this);
            // deprecated setting, but required on Android versions prior to 3.0
            mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        }

        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int weight,
                int height) {

            // If your preview can change or rotate, take care of those events here.
            // Make sure to stop the preview before resizing or reformatting it.

            if (mHolder.getSurface() == null){
              // preview surface does not exist
              return;
            }

            // stop preview before making changes
            try {
                mCamera.stopPreview();
            } catch (Exception e){
              // ignore: tried to stop a non-existent preview
            }

            // make any resize, rotate or reformatting changes here

            // start preview with new settings
            try {
                mCamera.setPreviewDisplay(mHolder);

                mCamera.startPreview();

            } catch (Exception e){
            }
        }

        @Override
        public void surfaceCreated(SurfaceHolder holder) {
            // TODO Auto-generated method stub
            // The Surface has been created, now tell the camera where to draw the preview.
            try {

                mCamera.setPreviewDisplay(holder);

                mCamera.startPreview();
            } catch (IOException e) {
            }
        }

        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {
            // TODO Auto-generated method stub

        }
    }

    @TargetApi(9)
    @Override
    public void onClick(View v) {

        switch (v.getId()) {
        case R.id.btn_cameraClick:



            // TODO Auto-generated method stub
            if(recording){

                try {
                    // stop recording and release camera
                    mediaRecorder.stop();  // stop the recording
                    releaseMediaRecorder(); // release the MediaRecorder object

                    //Exit after saved
                    Intent myIntent=new Intent(Videocapture.this,CameraPlay.class);
                    startActivity(myIntent);
                    finish();

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


            }else{

                //Release Camera before MediaRecorder start
                releaseCamera();


                if(!prepareMediaRecorder()){
                    Toast.makeText(Videocapture.this, 
                            "Fail in prepareMediaRecorder()!\n - Ended -", 
                            Toast.LENGTH_LONG).show();
                    finish();
                }

                //mCamera.setDisplayOrientation(90);
                mediaRecorder.start();

                recording = true;
                ///myButton.setText("STOP");

                myButton.setTag("STOP");





            }

            break;

        default:
            break;
        }


        // TODO Auto-generated method stub

    }

     @Override
        public void onBackPressed() {
            // do nothing.
            Intent myIntent =new Intent(Videocapture.this,AfterLoginHome.class);
            startActivity(myIntent);
            finish();
        }
}
</code></pre>

<p>Thanks in advance.</p>
