I saw there was a similar question here: Is it possible to record from the external mic when recording video in Android?
However, the question was never really answered and android documentation does not clearly state how this is done.
This person in this thread states that it is possible, but does not say how. Real-time audio capture and playback from an external mic
It would make sense for you to make the selection in the "setAudioSource" section, but none of the options are for external sources.
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_DOWNLINK);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
I am stuck with my app being 99% done. Any help would be greatly appreciated.
Is the external mic detected as a wired headset? If not, I don't think this is going to work. There's no such audio device as a "wired external microphone" in vanilla Android.
If it is detected as a wired headset it should be working out of the box if you use the MIC
or DEFAULT
AudioSource when recording. If it doesn't I'd say that's a flaw in the version of Android that you've got on your phone.
In my testing of USB Audio products, the MIC, DEFAULT, and VOICE_COMMUNICATION sources all switch to a USB Audio mic if it's connected. The CAMCORDER source always uses the built-in mic. I can't find any clear documentation of this, though. This page doesn't mention external/USB audio at all.
来源:https://stackoverflow.com/questions/16948769/recording-audio-from-external-source-in-an-android-application