Android MediaRecorder getMaxAmplitude always returns 0 on LG Optimus

I am writing an application that basically just checks if anything can be obtained from the microphone at all.

It works fine on multiple Android devices, but not on the LG Optimus. Every time I call MediaRecorder.getMaxAmplitudeon LG, it returns 0.

The device is successfully recording because I can listen to the recordings.

0
source share
3 answers

getMaxAmplitude returns the maximum amplitude since the last call.

So, the first time you call it, it initializes itself (and so returns 0) a second time, it should return a different value. According to the documentation:

getMaxAmplitude() , . setAudioSource().

, , 0

, , , . galaxyTab 7 (Froyo), 10.1 (Honeycomb).

EDIT: (, ). , getMaxAmplitude, , start(). :

recorder.prepare();
recorder.getMaxAmplitude();
recorder.start();
//listening to the user
int amplitude = recorder.getMaxAmplitude();

:

recorder.prepare();
recorder.start();
recorder.getMaxAmplitude();
//listening to the user
int amplitude = recorder.getMaxAmplitude();

EDIT. - . , S2. 0. getMaxAmplitude() , , , , .

+8

, . , , 0.0f.

private Runnable mPollTask = new Runnable() {
    public void run() {
            while(true){
           double amp = mSensor.getAmplitude();
           System.out.print("Amplitude: ");
           System.out.println(amp);
            }
    }
};
+1

Below code worked for me, I need to install setAudioSamplingRateandsetAudioEncodingBitRate

MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
if (Build.VERSION.SDK_INT >= 10) {
recorder.setAudioSamplingRate(44100);
recorder.setAudioEncodingBitRate(96000);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
} else {
// older version of Android, use crappy sounding voice codec
recorder.setAudioSamplingRate(8000);
recorder.setAudioEncodingBitRate(12200);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
}
recorder.setOutputFile(file.getAbsolutePath());
try {
recorder.prepare();
} catch (IOException e) {
throw new RuntimeException(e);
}
+1
source

All Articles