3

I'm trying to record the android mobile screen using Mediaprojection and Media Recorder. I'm able to record the screen along with audio using mic. Below is my code.

private void initRecorder() {
    try {
        File backupPath = Environment.getExternalStorageDirectory();

        backupPath = new File(backupPath.getPath()+"/VideoRecording");

        if (!backupPath.exists()) {
            backupPath.mkdirs();
        }
        mMediaRecorder = new MediaRecorder();


        mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
        mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        mMediaRecorder.setOutputFile(backupPath.getPath() + getFormattedDate()+".mp4");
        mMediaRecorder.setVideoSize(DISPLAY_WIDTH, DISPLAY_HEIGHT);
        mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
        mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        mMediaRecorder.setVideoEncodingBitRate(1500 * 1500);
        mMediaRecorder.setVideoFrameRate(30);
        int rotation = getWindowManager().getDefaultDisplay().getRotation();
        int orientation = ORIENTATIONS.get(rotation + 90);
        mMediaRecorder.setOrientationHint(orientation);
        mMediaRecorder.prepare();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

My Queries:

  1. How to record only the audio outcome from mobile. If i record through mic surrounding noise also getting recorded. I need to skip the outside noise and record only the audio from mobile.

  2. The recorded video size is as per mobile screen resolution. How to record the screen in different aspect ratio like 16:9?

alireza easazade
  • 3,324
  • 4
  • 27
  • 35
Vignesh
  • 2,295
  • 7
  • 33
  • 41

0 Answers0