Android video + audio recording

My goal is to capture video using an Android camera and record Voice from a microphone.

I googled the code but could not get any working example or code.

what i tried


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 get a RuntimeException

java.lang.RuntimeException: setAudioSource failed.

in the next line

 recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); 

tried with replacement

 recorder.setAudioSource(MediaRecorder.AudioSource.MIC); 

but it doesn’t work either.

+4
source share
2 answers

Remember 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" /> 
+4
source

This is a bug in android. See http://code.google.com/p/android/issues/detail?id=4075

You can simply try the following:

 recorder.setAudioSource(0); // Or 1, don't know which Enum is right. 

Since there is a mismatch in Enums.

+1
source

Source: https://habr.com/ru/post/1381479/


All Articles