Android examples for android.media:Audio
get Buffer Size for AudioRecord
import android.media.AudioFormat; import android.media.AudioRecord; public class Main { public static int getBufferSize() { return AudioRecord.getMinBufferSize(getMaxSampleRate(), android.media.AudioFormat.CHANNEL_IN_MONO, android.media.AudioFormat.ENCODING_PCM_16BIT); }/*from www . ja v a 2 s .co m*/ public static int getMaxSampleRate() { int maxSampleRate = -1; int[] possibleSampleRates = { 48000, 44100, 22050, 16000, 11025, 8000 }; for (int i = 0; i < possibleSampleRates.length; i++) { int bufferSize = AudioRecord.getMinBufferSize(possibleSampleRates[i], AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT); if (bufferSize > 0) { maxSampleRate = possibleSampleRates[i]; return maxSampleRate; } } return maxSampleRate; } }