I want to create a microphone app on Android that will receive sound through the microphone and play through the speakerphone but I don't know exactly what classes and services I should use.
The core of your answer is to:
A) record and store, as stated here.
MediaRecorder recorder = new MediaRecorder();
String status = Environment.getExternalStorageState();
if(status.equals("mounted")){
String path = Environment.getExternalStorageDirectory().toString()+"/YOURFOLDER"; // your custom path
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); // notice that this is the audio format, and you might want to change it to [other available audio formats][2]
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(path);
recorder.prepare();
// To start recording
recorder.start();
// To stop recording
recorder.stop();
recorder.release();
} else {
// Handle the situation
}
[Other available audio formats | 2]
B) Get recordings, as stated partially here. You should then show them.
try {
String path = Environment.getExternalStorageDirectory().toString()+"/YOURFOLDER"; // your custom path
File directory = new File(path);
File[] files = directory.listFiles();
} catch {
// Handle errors (or maybe no files in the directory)
}
C) Play recordings, as stated partially here.
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(Environment.getExternalStorageDirectory().toString()+"/YOURFOLDER"+"/yourfilename.formatextension"; // your custom pathare to use the file format and directory you used when saving
mp.prepare();
mp.start();
Hope this answer helps!