title: MediaRecorder rotating SurfaceView to match screen orientation
body: <p>I am currently attempting to create a video recorder using media recorder. The orientation of the video comes up rotated 90 degrees counter clockwise (basically landscape mode). I want it to be able to take a video whilst in portrait view.</p>
  
  <p>You can see from my code, that I am not directly calling the Camera variable to set in the media recorder, because it indicates the code is deprecated. Can anyone please help me.</p>
  
  <p>My code is as follows:</p>
  
  <pre><code>public void recordVideo() {
      isRecording = false;
      mediaRecorder = new MediaRecorder();
      initMediaRecorder();
  
      //recorderView is my surfaceView//
      surfaceHolder = recorderView.getHolder();
      surfaceHolder.addCallback(surfaceCallback);
      surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  
      toggleRecordButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              if (isRecording) {
                  mediaRecorder.stop();
                  timer.cancel();
                  mediaRecorder.release();
                  toggleRecordButton.setText("START");
  
                  mediaRecorderLayout.setVisibility(View.GONE);
                  mPictureHelper.fetchCompressedUri(Environment.getExternalStorageDirectory().getPath() + "/myVideo.mp4");
              } else {
                  seconds = 0;
                  mediaRecorder.start();
                  timer = new Timer();
                  timer.scheduleAtFixedRate(new TimerTask() {
                      @Override
                      public void run() {
                          getActivity().runOnUiThread(new Runnable() {
                              @Override
                              public void run() {
                                  if (seconds &lt; 10) {
                                      tvTimer.setText("00:0" + seconds);
                                  } else {
                                      tvTimer.setText("00:" + seconds);
                                  }
                                  seconds++;
                              }
                          });
                      }
                  }, 0, 1000);
                  isRecording = true;
                  toggleRecordButton.setText("STOP");
              }
          }
      });
  }
  private void initMediaRecorder() {
      String path = Environment.getExternalStorageDirectory().getPath() + "/myVideo.mp4";
  
      mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
      mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
      CamcorderProfile camcorderProfile_HQ = CamcorderProfile.get(CamcorderProfile.QUALITY_480P);
      mediaRecorder.setProfile(camcorderProfile_HQ);
      mediaRecorder.setOutputFile(path);
  
      mediaRecorder.setMaxDuration(60000); // Set max duration 60 sec.
      mediaRecorder.setMaxFileSize(10000000);
  }
  SurfaceHolder.Callback surfaceCallback = new SurfaceHolder.Callback() {
      @Override
      public void surfaceCreated(SurfaceHolder holder) {
          prepareMediaRecorder();
      }
      @Override
      public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
      }
      @Override
      public void surfaceDestroyed(SurfaceHolder holder) {
      }
  };
  private void prepareMediaRecorder() {
      mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
      try {
          mediaRecorder.prepare();
      } catch (IllegalStateException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>I have checked out other posts regarding this, but they all seem outdated due to the fact that alot of the code that used to be used is now deprecated. I hope someone can help.</p>