Reputation: 31
I'm trying to make an app that records your voice through default mic of the device but I'm running into some complications.
I'm using this line to make it clear the source of audio ( which is MIC )
MediaRecorder mprec = MediaRecorder.AudioSource.MIC;
mprec.start();
But I face an error in android studio:
: required android.media.MediaRecorder found : Int (MIC)
It happens when I try to put MIC or anything else after AudioSource.
Any ideas how I can solve this?
Upvotes: 2
Views: 768
Reputation: 28278
From the Android Documentation:
mRecorder = new MediaRecorder();//INTERESTING
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);//INTERESTING
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(mFileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
mRecorder.prepare();
} catch (IOException e) {
Log.e(LOG_TAG, "prepare() failed");
}
mRecorder.start();
Note the //INTERESTING
comment; That is the key where you see how you should do it.
First you create the MediaRecorder and then apply the audio source as (in your case) the/a microphone.
Upvotes: 2