skip to Main Content

How I can record video only with MediaRecorder? I found the solution that simply leaving out the AudioSource will do that but unfortunately doesn’t work on Android 10+. If I do that MediaRecorder.prepare() fails. I can’t find a solution on the internet.

Thanks

2

Answers


  1. Prepare your media recorder in the following sequence.
    Only set AudioSource and AudioEncoder if you want to record with sound.

         MediaRecorder mMediaRecorder = new MediaRecorder();
        if (recordWithSound == true) {
            mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        }
        mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
        mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        mMediaRecorder.setVideoSize(DISPLAY_WIDTH, DISPLAY_HEIGHT);
        mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
        if (recordWithSound == true) {
            mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        }
        mMediaRecorder.setVideoEncodingBitRate(videoBitRate);
        mMediaRecorder.setVideoFrameRate(videoFrameRate);
        mMediaRecorder.setOrientationHint(orientation);
        mMediaRecorder.setOutputFile(videoFile);
        mMediaRecorder.prepare();
    
    Login or Signup to reply.
  2. I have done that i have mute mic on button click if you want to mute when recording start than paste the code in your startRecording()

        val audioManager = applicationContext.getSystemService(AUDIO_SERVICE) as AudioManager
        audioManager.isMicrophoneMute = false
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search