title: Video recorder app in Android
body: <p>I'm new to Android and Java so forgive me if the answer is obvious, but I can't get my video recorder app to work.  I can see the image just fine in the camera preview (that code works fine) but when I go to record, I only record sound.  I've implemented the code fragments recommended by Google (below) but it's not working.  I've tried everything I can think of.  Any insight would be appreciated.</p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
      int x;
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_video_camera);
  
      // if (savedInstanceState == null) {
      //  getSupportFragmentManager().beginTransaction()
      //          .add(R.id.container, new PlaceholderFragment()).commit();
      // Create an instance of Camera
      x =  Camera.getNumberOfCameras();
      mCamera = getCameraInstance(x-1);
      recorder = new MediaRecorder();
  
      // Create our Preview view and set it as the content of our activity.
      mPreview = new VideoCameraPreview(this, x-1, mCamera);
      FrameLayout preview = (FrameLayout) findViewById(R.id.video_camera_preview);
      preview.addView(mPreview);
  
      try {
          mCamera.setPreviewDisplay(VideoCameraPreview.mHolder);
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      // Add a listener to the Capture button
      final Button captureButton = (Button) findViewById(R.id.button_capture);
  
      captureButton.setOnClickListener(
          new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  if (isRecording) {
                      // stop recording and release camera
                      recorder.stop();  // stop the recording
                      // releaseMediaRecorder(); // release the MediaRecorder object
                      mCamera.lock();         // take camera access back from MediaRecorder
  
                      // inform the user that recording has stopped
                      captureButton.setText("Capture");
                      isRecording = false;
                  } else {
                      // initialize video camera
                      if (prepareVideoRecorder()) {
                          // Camera is available and unlocked, MediaRecorder is prepared,
                          // now you can start recording
                          recorder.start();
  
                          // inform the user that recording has started
                          captureButton.setText("Stop");
                          isRecording = true;
                      } else {
                          // prepare didn't work, release the camera
                          releaseMediaRecorder();
                          // inform user
                      }
                  }
              }
          }
      );
  
  }
  
  private boolean prepareVideoRecorder (){
      //Record a video in response to a user pressing the button
  
      int x = Camera.getNumberOfCameras();
  
      mCamera.unlock();  //Unlock the camera for use by the Media Recorder
      recorder.setCamera(mCamera); // Get the camera ready for recording
      recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
      recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
      recorder.setProfile(CamcorderProfile.get(x-1, CamcorderProfile.QUALITY_HIGH));
  
      recorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO).toString());
      recorder.setPreviewDisplay(VideoCameraPreview.mHolder.getSurface());
  
      try {
          recorder.prepare();
      } catch (IllegalStateException e) {
          Log.d("Wink", "Illegal stateException preparing MediaRecorder: " + e.getMessage());
          recorder.release();
          return false;
      } catch (IOException e) {
          Log.d("Wink", "IOException preparing MediaRecorder: " + e.getMessage());
          recorder.release();
          return false;
      }
  
      return true;
  }       
  </code></pre>