I want to create an Android app in which I have to react if the amplitude of the microphone reaches a definite level.
Right now I'm using this Code:
MediaRecorder soundRecorder = new MediaRecorder();
soundRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
soundRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
soundRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
soundRecorder.setOutputFile("/dev/null");
soundRecorder.prepare();
soundRecorder.start();
int amplitude = 0;
while (amplitude < MyApp.this.ampToReact) {
amplitude = soundRecorder.getMaxAmplitude();
}
But I know that this is very bad programming (and my app keeps crashing).
So I would like to create a listener with an onAmplitudeReachedDefiniteLevel()
method to replace this ugly while loop.