Search code examples
androidvideo-captureandroid-camera

Video + Audio Recorder Android


My Goal is to capture Video using Android Camera and Record Voice from Mic.

I googled code but couldn't get any working example or code.

what I've tried is


        recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
        recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);

        CamcorderProfile cpHigh = CamcorderProfile
                .get(CamcorderProfile.QUALITY_HIGH);
        recorder.setProfile(cpHigh);
        recorder.setOutputFile("/sdcard/videocapture_example.mp4");
        recorder.setMaxDuration(50000); // 50 seconds
        recorder.setMaxFileSize(5000000); // Approximately 5 megabytes

        recorder.setVideoSize(320, 240); 
        recorder.setVideoFrameRate(15); 

I'm getting a RuntimeException

java.lang.RuntimeException: setAudioSource failed.

on the following line

recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);

tried with replacing

recorder.setAudioSource(MediaRecorder.AudioSource.MIC);

but this doesn't work either.


Solution

  • Don't forget to set permissions in manifest.xml

    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.RECORD_VIDEO"/>
    <uses-permission android:name="android.permission.CAMERA" />