首页 > 解决方案 > 带有内部音频的 Android 屏幕录像机

问题描述

我正在尝试使用Mediaprojectionand记录 android 手机屏幕Media Recorder。我可以使用麦克风录制屏幕和音频。下面是我的代码。

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();
    }
}

我的查询:

  1. 如何仅记录来自移动设备的音频结果。如果我通过麦克风录音,周围的噪音也会被录音。我需要跳过外部噪音,只记录手机的音频。

  2. 录制的视频大小以手机屏幕分辨率为准。如何录制不同纵横比的屏幕,如 16:9?

标签: androidandroid-mediarecorderandroid-screenscreen-recordingandroid-mediaprojection

解决方案


推荐阅读